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 这样我们就可以不重不漏的按照状态转移 但是复杂度确实不大行(减了两个常数卡过去的 ...
随机推荐
- Hyperledger Fabric-sdk-java
Hyperledger Fabric-sdk-java 2018年04月18日 23:36:02 l_ricardo 阅读数 975更多 分类专栏: 区块链 java 版权声明:本文为博主原创文章 ...
- 树莓派和STM32通过USB和串口通信记录
不管怎样,为了简便开发,通信选择串口通信. 推荐文章:https://blog.csdn.net/magnetoooo/article/details/53564797 推荐测试工具:https:// ...
- Java EE javax.servlet中的RequestDispatcher接口
RequestDispatcher接口 public interface RequestDispatcher 一.介绍 定义一个对象,从客户端接收请求并将其发送到服务器上的任何资源(例如servlet ...
- 05docker仓库---搭建本地仓库
Docker仓库 仓库(Repository)是集中存放镜像的地方,分别公有仓库和私有仓库. 注册服务器是存放仓库的具体服务器.一个注册服务器上可以有多个仓库,每一个仓库里面可以有多个镜像. eg:仓 ...
- MVC4学习要点记三
一.数据迁移用来解决code first情况下当增加.删除.改变实体类,或改变DbContext类后,相应地更新数据库结构而不会对现有数据产生影响. 1.启用迁移指令:enable-migration ...
- 【题解】P3391 文艺平衡树
用pb_ds库中的rope水过去的,忽然发现这玩意能水好多模拟题. 详见这个博客:背景的小姐姐真的好看 声明 #include <ext/rope> using namespace __g ...
- SpringBoot整合MyBatis的分页插件PageHelper
1.导入依赖(maven) <dependency> <groupId>com.github.pagehelper</groupId> <artifactId ...
- java实现spark常用算子之SaveAsTextFile
import org.apache.spark.SparkConf;import org.apache.spark.api.java.JavaRDD;import org.apache.spark.a ...
- mysql 关于字符串搜索的函数
与like作用相似 FIND_IN_SET LOCATE POSITION
- BLE 5协议栈-通用属性规范层(GATT)
文章转载自:http://www.sunyouqun.com/2017/04/page/2/ 通用属性规范GATT(Generic Attribute Profile)将ATT层定义的属性打包成不同的 ...