题目链接

问题分析

比较显见的容斥,新颖之处在于需要把横竖一起考虑……

可以枚举没有\(1\)的行数和列数,答案就是

\[\sum\limits_{i=0}^n\sum\limits_{j=0}^m(-1)^{i+j}{n\choose i}{n \choose j}(k-1)^{i*n+j*n-i*j}k^{n*n-i*n-j*n+i*j}
\]

个数算对就好了……

参考程序

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

  1. Another Filling the Grid

    E. Another Filling the Grid 参考:Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 容斥这个东 ...

  2. [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理)

    [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理) 题面 一个\(n \times n\)的格子,每个格子里可以填\([1,k]\)内的整数. ...

  3. 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 ...

  4. 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 ...

  5. codeforces#1228E. Another Filling the Grid(容斥定理,思维)

    题目链接: https://codeforces.com/contest/1228/problem/E 题意: 给n*n的矩阵填数,使得每行和每列最小值都是1 矩阵中可以填1到$k$的数 数据范围: ...

  6. 【CF589 E】Another Filling the Grid

    一个很套路的容斥裸题,这里记录一下scb 的切题过程 Description 有一个 \(n\times n\) 的矩阵,你需要往每格里填一个 \([1,k]\) 的整数,使得每一行.每一列的最小值都 ...

  7. Codeforces 1228E. Another Filling the Grid

    传送门 看到 $n=250$ 显然考虑 $n^3$ 的 $dp$ 设 $f[i][j]$ 表示填完前 $i$ 行,目前有 $j$ 列的最小值是 $1$ 的合法方案数 那么对于 $f[i][j]$ ,枚 ...

  8. [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 ...

  9. Codeforces Round #589 (Div. 2) Another Filling the Grid (dp)

    题意:问有多少种组合方法让每一行每一列最小值都是1 思路:我们可以以行为转移的状态 附加一维限制还有多少列最小值大于1 这样我们就可以不重不漏的按照状态转移 但是复杂度确实不大行(减了两个常数卡过去的 ...

随机推荐

  1. HTML之盒子变形动画

    4个圆形球作圆周运动 代码: <div class="box"> <div class="box1"></div> < ...

  2. 浅谈RPC框架

    RPC(Remote Promote Call) RPC(Remote Promote Call):一种进程间通信方式.允许像调用本地服务一样调用远程服务. RPC框架的主要目标就是让远程服务调用更简 ...

  3. 解决IDEA报错Could not autowire. There is more than one bean of 'xxx' type

    更新项目之后IDEA突然出现了这样的报错信息.显示Could not autowire. There is more than one bean of 'xxx' type.这个错误的意思是xxx类型 ...

  4. 第九章、import 和from ...import

    目录 第九章.import 和from ...import 一.import和 from ...import ... 二.import模块名 第九章.import 和from ...import 一. ...

  5. redis-cluster集群总结

    Redis集群搭建 要想搭建一个最简单的Redis集群,那么至少需要6个节点:3个Master和3个Slave.为什么需要3个Master呢?如果你了解过Hadoop/Storm/Zookeeper这 ...

  6. another-redis-desktop-manager

    brew cask install another-redis-desktop-manager

  7. spring JdbcTemplate如何返回多个结果集

    最近很少发博客,先是去了***公司呆了几年,完全不能上外网,后来又出来了,能上外网了,但项目太忙一直在打码,用的语言也从C#换成了JAVA. 好在两者比较相似,转起来还算方便,近日在操作sqlserv ...

  8. zencart设置默认货币三种方法

    zencart设置默认货币为USD 方法一:mysql UPDATE configuration SET configuration_value = 'USD' WHERE configuration ...

  9. p2456二进制方程 题解

    题面描述:可以跳过 一个形如: X1X2…Xn=Y1Y2..Ym 的等式称为二进制方程. 在二进制方程的两边:Xi和Yj (1<=i<=n:1<=j<=m)是二进制数字(0.1 ...

  10. 自动生成SSM框架

    使用idea 新创建项目 然后 新创建 java .resources 文件夹...... 图上是项目结构 java文件夹下的 文件夹 命名规范 com.nf147(组织名)+ oukele(作者) ...