CF1228E Another Filling the Grid
问题分析
比较显见的容斥,新颖之处在于需要把横竖一起考虑……
可以枚举没有\(1\)的行数和列数,答案就是
\]
个数算对就好了……
参考程序
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL Mod = 1000000007;
const LL Maxn = 260;
LL n, k;
LL Fact[ Maxn ], INV[ Maxn ];
LL Pow( LL x, LL y ) {
LL Ans = 1;
for( ; y; y >>= 1, x = x * x % Mod )
if( y & 1 )
Ans = Ans * x % Mod;
return Ans;
}
LL C( LL n, LL m ) {
return Fact[ n ] * INV[ m ] % Mod * INV[ n - m ] % Mod;
}
int main() {
Fact[ 0 ] = 1;
for( LL i = 1; i < Maxn; ++i ) Fact[ i ] = Fact[ i - 1 ] * i % Mod;
INV[ Maxn - 1 ] = Pow( Fact[ Maxn - 1 ], Mod - 2 );
for( LL i = Maxn - 2; i >= 0; --i ) INV[ i ] = INV[ i + 1 ] * ( i + 1 ) % Mod;
scanf( "%lld%lld", &n, &k );
LL Ans = 0;
for( LL i = 0; i <= n; ++i )
for( LL j = 0; j <= n; ++j ) {
LL Num = ( i + j ) * n - i * j;
LL t1 = C( n, i ) * C( n, j ) % Mod;
LL Method = t1 * Pow( k - 1, Num ) % Mod * Pow( k, n * n - Num ) % Mod;
if( ( i + j ) % 2 == 0 ) Ans = ( Ans + Method ) % Mod;
else Ans = ( Ans + Mod - Method ) % Mod;
}
printf( "%lld\n", Ans );
return 0;
}
CF1228E Another Filling the Grid的更多相关文章
- Another Filling the Grid
E. Another Filling the Grid 参考:Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 容斥这个东 ...
- [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理)
[Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理) 题面 一个\(n \times n\)的格子,每个格子里可以填\([1,k]\)内的整数. ...
- Codeforces Round #589 (Div. 2) E. Another Filling the Grid(DP, 组合数学)
链接: https://codeforces.com/contest/1228/problem/E 题意: You have n×n square grid and an integer k. Put ...
- Codeforces Round #589 (Div. 2) B. Filling the Grid
链接: https://codeforces.com/contest/1228/problem/B 题意: Suppose there is a h×w grid consisting of empt ...
- codeforces#1228E. Another Filling the Grid(容斥定理,思维)
题目链接: https://codeforces.com/contest/1228/problem/E 题意: 给n*n的矩阵填数,使得每行和每列最小值都是1 矩阵中可以填1到$k$的数 数据范围: ...
- 【CF589 E】Another Filling the Grid
一个很套路的容斥裸题,这里记录一下scb 的切题过程 Description 有一个 \(n\times n\) 的矩阵,你需要往每格里填一个 \([1,k]\) 的整数,使得每一行.每一列的最小值都 ...
- Codeforces 1228E. Another Filling the Grid
传送门 看到 $n=250$ 显然考虑 $n^3$ 的 $dp$ 设 $f[i][j]$ 表示填完前 $i$ 行,目前有 $j$ 列的最小值是 $1$ 的合法方案数 那么对于 $f[i][j]$ ,枚 ...
- [Codeforces 1228E]Another Filling the Grid(组合数+容斥)
题目链接 解题思路: 容斥一下好久可以得到式子 \(\sum_{i=0}^{n}\sum_{j=0}^{n}(-1)^{i+j}C_n^iC_n^j(k-1)^{ni+nj-ij}k^{n^2-(ni ...
- Codeforces Round #589 (Div. 2) Another Filling the Grid (dp)
题意:问有多少种组合方法让每一行每一列最小值都是1 思路:我们可以以行为转移的状态 附加一维限制还有多少列最小值大于1 这样我们就可以不重不漏的按照状态转移 但是复杂度确实不大行(减了两个常数卡过去的 ...
随机推荐
- java 异常捕捉 ( try catch finally ) 你真的掌握了吗?
掌握下面几条原则就可以完全解决“当try.catch.finally遭遇return”的问题. 原则:1.finally语句块中的代码是一定会执行的,而catch块中的代码只有发生异常时才会执行. 2 ...
- ASP.NET使用AJAX应注意IIS有没有.ashx扩展
项目添加引用AJAX.DLL了:今天将本地做好的一个web程序放到服务器上,居然报告错误了.web程序使用了ajax来往返数据. 检查生成的html语句,有这么两句代码<script type= ...
- 【原创】大数据基础之ETL vs ELT or DataWarehouse vs DataLake
ETL ETL is an abbreviation of Extract, Transform and Load. In this process, an ETL tool extracts the ...
- luogu题解P1032字串变换--BFS+STL:string骚操作
题目链接 https://www.luogu.org/problemnew/show/P1032 分析 这题本来很裸的一个BFS,发现其中的字符串操作好烦啊.然后就翻大佬题解发现用STL中的strin ...
- HTML的学习2(注释)
<!--链接标签--> <!--核心属性就是href 属性值可以是一个跳转的地址--> <a href="">可点击的文本</a> ...
- uni app以及小程序 --环境搭建以及编辑器
https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html 根据以上网页下载自己电脑相应的版本的微信开发者工具(目录 ...
- conda查找安装包的版本以及安装特定版本的包
如下图 想要安装特定版本的torchvision,然后conda search torchvision,能够列出conda云上所有的安装包 然后,安装包的时候,conda install 包名=版本就 ...
- hdfs存储与数据同步
两个hadoop集群之间同步数据 实例为dws的 store_wt_d表 一 文件拷贝 hadoop distcp -update -skipcrccheck hdfs://10.8.31.14:80 ...
- 剖析isinstance的实现机制
python的自省机制也是其一大彪悍的特性,对于任何一个对象,我们都可以准确的获取其类型. print(type(123)) print(type("")) print(type( ...
- Java 通过Math.random() 生成6位随机数
public static void main(String[] args) { String sjs=""; for (int i = 0; i < 6; i++) { i ...