Another Filling the Grid
参考:Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理
容斥这个东西可以理解,但是运用到实际的时候,还是觉得有点迷迷糊糊的,不知道套公式会不会是一种可行的办法。
是时候也得把以前的知识温习一下了....
具体的思路看参考的博客就可以理解了。
代码:
// Created by CAD on 2019/10/2.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
ll qpow(ll x,ll n)
{
ll re=1;
while(n)
{
if(n&1) re=(re*x)%mod;
n>>=1,x=(x*x)%mod;
}
return re;
}
ll c[300][300];
int main()
{
ll n,k; cin>>n>>k;
for(int i=0;i<=250;++i)
{
c[i][0]=c[i][i]=1;
for(int j=1;j<i;++j)
c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
}
ll ans=0;
for(int i=0;i<=n;++i)
for(int j=0;j<=n;++j)
{
ans=(ans+((i+j)&1?-1:1)*c[n][i]%mod*c[n][j]%mod*
qpow(k-1,n*(i+j)-i*j)%mod*qpow(k,n*n-n*(i+j)+i*j)%mod+mod)%mod;
}
cout<<ans<<endl;
}
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]$ ,枚 ...
- CF1228E Another Filling the Grid
题目链接 问题分析 比较显见的容斥,新颖之处在于需要把横竖一起考虑-- 可以枚举没有\(1\)的行数和列数,答案就是 \[ \sum\limits_{i=0}^n\sum\limits_{j=0}^m ...
- [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 这样我们就可以不重不漏的按照状态转移 但是复杂度确实不大行(减了两个常数卡过去的 ...
随机推荐
- 使用kafka-eagle监控Kafka
# 监控kafka集群,开启监控趋势图使用 # 有一个问题,需要在kafka-server-start.sh文件中配置端口,有如下三种办法 # 第一种:复制并修改kafka目录,比如kafka-1,k ...
- 01docker基本概念
docker基本概念 官方文档URL:https://docs.docker.com/ 1.Docker的构想是要实现"Build, Ship and Run Any App, Anywhe ...
- Dev-C++的一些使用技巧快捷键
最近开始用Dev-C++在Window下编程,感觉Dec-C++是一款挺不错的C++编译器.下载地址http://www.duote.com/soft/9830.html .现总结一些使用技巧: 1. ...
- CentOS6.8安装Python3.6.3
1.linux下安装python3 准备编译环境(环境如果不对的话,可能遇到各种问题,比如wget无法下载https链接的文件) yum install zlib-devel bzip2-devel ...
- Facebook团队合影
今晚公司年会,晚上有些人不去,我晚上要带孩子,也不去,大家就说那我们中午照个合照吧.没啥子准备,大家都一副油腻的样子.除了要去party的化了妆.
- linux mint 安装微信
安装nodejs 到nodejs官网下载node js压缩包,然后解压到自己设置的目录.我的解压路径是 /home/congwiny/Develop/SoftWare/node-v6.10.3-lin ...
- Entity Framework:三种开发模式实现数据访问
原文地址 http://blog.csdn.net/syaguang2006/article/details/19606715 前言 Entity Framework支持Database First. ...
- SVN主从备份
SVN主从备份 两套环境:192.168.67.63(主SVN) 192.168.67.60(从SVN) 1.主环境上已经装好SVN并且存在数据仓库/home/svndata在从环境上,新建一/hom ...
- axios+post获取并下载后台返回的二进制流
axios+post获取并下载后台返回的二进制流 let url = $.getCookie('prefixUrl')+'/expenseword/exportWords'; let vm = thi ...
- SYSLINUX官方文档
帮助正确认识SYSLINUX http://www.syslinux.org/wiki/index.php/Doc/syslinux http://www.syslinux.org/wiki/inde ...