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的更多相关文章

  1. @atcoder - AGC035F@ Two Histograms

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 N*M 的方格,我们通过以下步骤往里面填数: (1)将 ...

  2. ZROI 暑期高端峰会 A班 Day1 组合计数

    AGC036F Square Constriants 一定有 \(l_i<p_i\le r_i\). 考虑朴素容斥,枚举每个数是 \(\le l_i\) 还是 \(\le r_i\).对于 \( ...

  3. 【AGC035F】Two Histograms

    Problem Description 你有一个 \(N\) 行.\(M\) 列的.每个格子都填写着 0 的表格.你进行了下面的操作: 对于每一行 \(i\) ,选定自然数 \(r_i\) (\(0\ ...

  4. Face recognition using Histograms of Oriented Gradients

    Face recognition using Histograms of Oriented Gradients 这篇论文的主要内容是将Hog算子应用到人脸识别上. 转载请注明:http://blog. ...

  5. 行人检測之HOG特征(Histograms of Oriented Gradients)

    之前的文章行人计数.计次提到HOG特征这个概念,这两天看了一下原版的论文,了解了一下HOG特征的原理,并依据自己的理解将这种方法的流程写了下来,假设有不正确的地方欢迎指正. HOG(Histogram ...

  6. Intermediate Python for Data Science learning 2 - Histograms

    Histograms from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotlib? ...

  7. (转)梯度方向直方图HOG(Histograms of Oriented Gradients )

    HOG(Histograms of Oriented Gradients )梯度方向直方图 方向梯度直方图(Histogram of Oriented Gradient, HOG)特征是一种在计算机视 ...

  8. [翻译]——MySQL 8.0 Histograms

    前言: 本文是对这篇博客MySQL 8.0 Histograms的翻译,翻译如有不当的地方,敬请谅解,请尊重原创和翻译劳动成果,转载的时候请注明出处.谢谢! 英文原文地址:https://lefred ...

  9. Histograms of Sparse Codes for Object Detection用于目标检测的稀疏码直方图

    AbstractObject detection has seen huge progress in recent years, much thanks to the heavily-engineer ...

随机推荐

  1. <authentication> 元素

    <authentication> 元素 配置 ASP.NET 身份验证支持.该元素只能在计算机.站点或应用程序级别声明.如果试图在配置文件中的子目录或页级别上进行声明,则将产生分析器错误信 ...

  2. oozie与hue整合 执行WC案例报错: 连接10020端口被拒绝

    Call From hdp-05/192.168.230.15 to hdp-01:10020 failed on connection exception: java.net.ConnectExce ...

  3. Azure IoT 技术研究系列1

    物联网技术已经火了很多年了,业界各大厂商都有各自成熟的解决方案.我们公司主要搞新能源汽车充电,充电桩就是我们物联网技术的最大应用,车联网.物联网. 互联网三网合一.作为Azure重要的Partner和 ...

  4. C++ GUI Qt4学习笔记07

    C++ GUI Qt4   qtc++scrollobject编程 事件(event)是由串口系统或者Qt自身产生的,用以响应所发生的各类事情.当用户按下或者松开键盘或者鼠标上的按键时,就可以产生一个 ...

  5. HDU 5418 Victor and World (状态压缩dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5418 题目大意:有n个结点m条边(有边权)组成的一张连通图(n <16, m<100000 ...

  6. c++ string转char*

    1.如果要将string转换为char*,可以使用string提供的函数c_str() ,或是函数data(),data除了返回字符串内容外,不附加结束符'\0',而c_str()返回一个以‘\0’结 ...

  7. 利用BeautifulSoup爬去我爱我家的租房数据

    因为之前对BeautifulSoup一直不是很熟悉,刚好身边的朋友同事在找房子,就想着能不能自己写个爬虫爬一下数据,因此就写了这个爬虫.基本都是边看书边写的,不过也没什么好讲的.直接粘代码了. # c ...

  8. 理解厂商前缀 -webkit- / -moz- / -ms- / -o-

    CSS3规范如果想要达到W3C的推荐标准状态还需要不断改进.浏览器则通常在W3C开发标准的过程中就会体现这些特性.这样,标准在最终敲定之前就能知道哪些地方还能进一步改进. 在包含某个特性的的初始阶段, ...

  9. centos搭建lamp环境参考(根据腾讯云实验室)

    1.安装MYSQL 使用 yum 安装 MySQL: yum install mysql-server -y 安装完成后,启动 MySQL 服务: service mysqld restart 设置 ...

  10. new Date(str)返回 Invalid date问题

    var date=new Date($("input[name='mettingTime']").val().replace(/-/g, "/")); var ...