[AGC035F]Two Histograms
Description
你有一个 \(N\) 行、\(M\) 列的、每个格子都填写着 0 的表格。你进行了下面的操作:
对于每一行 \(i\) ,选定自然数 \(r_i\ (0 ≤ r i ≤ M )\)
,将这一行最左边的 \(r_i\) 个格子中
的数 \(+1\).对于每一列 \(i\) ,选定自然数 \(c_i\ (0 ≤ c i ≤ N )\)
,将这一列最上边的 \(c_i\) 个格子中
的数 \(+1\).
这样,根据你选定的 \(r_1 , r_2 , . . . , r_N , c_1 , c_2 , . . . , c_M\) ,你就得到了一个每个格子要 么是 \(0\) ,要么是 \(1\) ,要么是 \(2\) 的一个最终的表格。
问本质不同的最终表格有多少种。 两个表格本质不同当且进当它们有一个对应格子中的数不同。
\(n, m\le 5\times 10^5\)
Solution
csy的题解:
组合数那里上下写反了,乘上 \(k!\) 是为了让选出来的k行k列一一匹配上,可以固定一个,另一个排列,就是 \(k!\).
Code
#include <iostream>
#include <cstdio>
#define LL long long
using namespace std;
const int maxN = (int) 5e5;
const int mod = (int) 998244353;
LL qpow(LL a, LL b)
{
LL ans = 1;
while (b)
{
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
int n, m, ans;
int fac[maxN + 2], ifac[maxN + 2];
void init(int n)
{
fac[0] = 1;
for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
ifac[n] = qpow(fac[n], mod - 2);
for (int i = n - 1; i >= 0; --i) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % mod;
}
int C(int n, int m)
{
if (n < 0 || m < 0 || m > n) return 0;
return 1ll * fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("AGC035F.in", "r", stdin);
freopen("AGC035F.out", "w", stdout);
#endif
scanf("%d%d", &n, &m);
if (n < m) swap(n, m);
init(n);
for (int k = 0; k <= m; ++k)
{
ans += 1ll * qpow(-1, k) * C(n, k) % mod * C(m, k) % mod * fac[k] % mod * qpow(m + 1, n - k) % mod * qpow(n + 1, m - k) % mod;
ans %= mod;
(ans += mod) %= mod;
}
printf("%d\n", (1ll * ans + mod) % mod);
}
[AGC035F]Two Histograms的更多相关文章
- @atcoder - AGC035F@ Two Histograms
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 N*M 的方格,我们通过以下步骤往里面填数: (1)将 ...
- ZROI 暑期高端峰会 A班 Day1 组合计数
AGC036F Square Constriants 一定有 \(l_i<p_i\le r_i\). 考虑朴素容斥,枚举每个数是 \(\le l_i\) 还是 \(\le r_i\).对于 \( ...
- 【AGC035F】Two Histograms
Problem Description 你有一个 \(N\) 行.\(M\) 列的.每个格子都填写着 0 的表格.你进行了下面的操作: 对于每一行 \(i\) ,选定自然数 \(r_i\) (\(0\ ...
- Face recognition using Histograms of Oriented Gradients
Face recognition using Histograms of Oriented Gradients 这篇论文的主要内容是将Hog算子应用到人脸识别上. 转载请注明:http://blog. ...
- 行人检測之HOG特征(Histograms of Oriented Gradients)
之前的文章行人计数.计次提到HOG特征这个概念,这两天看了一下原版的论文,了解了一下HOG特征的原理,并依据自己的理解将这种方法的流程写了下来,假设有不正确的地方欢迎指正. HOG(Histogram ...
- Intermediate Python for Data Science learning 2 - Histograms
Histograms from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotlib? ...
- (转)梯度方向直方图HOG(Histograms of Oriented Gradients )
HOG(Histograms of Oriented Gradients )梯度方向直方图 方向梯度直方图(Histogram of Oriented Gradient, HOG)特征是一种在计算机视 ...
- [翻译]——MySQL 8.0 Histograms
前言: 本文是对这篇博客MySQL 8.0 Histograms的翻译,翻译如有不当的地方,敬请谅解,请尊重原创和翻译劳动成果,转载的时候请注明出处.谢谢! 英文原文地址:https://lefred ...
- Histograms of Sparse Codes for Object Detection用于目标检测的稀疏码直方图
AbstractObject detection has seen huge progress in recent years, much thanks to the heavily-engineer ...
随机推荐
- windows 10 安装openssh 0x800f0954 的一种解决方法
安装与卸载参考:https://docs.microsoft.com/zh-cn/windows-server/administration/openssh/openssh_install_first ...
- python模块与包的详解
一模块 1.什么是模块? 常见场景:一个模块包含python定义和声明的文件,文件名就是模块名字加上.py的后缀 2.为何要是用模块 如果你退出python解释器然后重新进入,那么你之前定义的函数或者 ...
- java tomcat虚拟目录的深入了解
我们知道,Web网站中的内容(包括网页,图片,音频文件等)一般都存放在App的目录下.但随着网站内容的不断丰富,用户需要把不同层次的内容组织成网站的子目录.我们通常的做法是在网站主目录下新建子目录,并 ...
- flask中自定义日志类
一:项目架构 二:自定义日志类 1. 建立log.conf的配置文件 log.conf [log] LOG_PATH = /log/ LOG_NAME = info.log 2. 定义日志类 LogC ...
- [原创]Laravel 基于redis队列的解析
目录 参考链接 本文环境 为什么使用队列 Laravel 中的队列 分发任务 任务队列 Worker Last-Modified: 2019年5月10日11:44:18 参考链接 使用 Laravel ...
- [原创]PHP代码修正之CodeSniffer
目录 参考链接 介绍 安装 使用 命令行模式 PHPStorm 让编辑器使用PSR-2标准 集成phpcbf 参考链接 PHP开发规范之使用phpcbf脚本自动修正代码格式 在PhpStorm中使用P ...
- HRESULT: 0x80040228
When run the arcgis engine codes in the console application, may come to the exception: HRESULT: 0x8 ...
- 转:HTML5 History API 详解
从Ajax翻页的问题说起 请想象你正在看一个视频下面的评论,在翻到十几页的时候,你发现一个写得稍长,但非常有趣的评论.正当你想要停下滚轮细看的时候,手残按到了F5.然后,页面刷新了,评论又回到了第一页 ...
- 【bzoj1176】[Balkan2007]Mokia
题目描述: 维护一个W*W的矩阵,初始值均为S.每次操作可以增加某格子的权值,或询问某子矩阵的总权值.修改操作数M<=160000,询问数Q<=10000,W<=2000000. 输 ...
- sh_01_hello
sh_01_hello print("hello python") print("你好世界")