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面试知识点汇总
Java面试知识点汇总 置顶 2019年05月07日 15:36:18 温柔的谢世杰 阅读数 21623 文章标签: 面经java 更多 分类专栏: java 面试 Java面试知识汇总 版权声明 ...
- shiro学习(四、shiro集成spring+springmvc)
依赖:spring-context,spring-MVC,shiro-core,shiro-spring,shiro-web 实话实说:web.xml,spring,springmvc配置文件好难 大 ...
- 封装一些简单的 dom 操作
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 编辑docker容器中的文件
一般docker中没有VI或者其它相应的文本编辑器,为了写个东西安装个vi就可以解决问题,除此之外还有别的办法 登陆docker中找到需要编辑的文件的位置 sudo docker ps -a sudo ...
- hadoop 中ALL Applications 中Tracking 下History查找不到MapReduce Job 日志
运行一个Map Reduce job 想查看日志: 点击History ,找不到网页 解决办法如下: 1.其中有一个进程是需要启动的: Hadoop自带了一个历史服务器,可以通过历史服务器查看已经运行 ...
- 红队基础设施建设:隐藏你的C2
0x01 前言 待定
- 【转】bitbake 笔记
原文 http://blog.csdn.net/xiaofeng_yan/article/details/6757725 1 当你已经编完一个系统比如sato映像,在编一个meta-toolchain ...
- 关于php 7.4编译安装
一个不错的文章 https://hqidi.com/150.html 贴个地址就好啦, 借鉴了一把,很良心
- servlet遇到的问题
1 创建web项目没有xml自动生成 2 servlet 忽然报奇怪500错误 出现的BUG原因 JAVA bean没有设置 自动导入了其他User包
- java-接口—策略模式
策略模式,就是不同类继承相同的接口,实现不同的策略.