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

题意:问有多少种组合方法让每一行每一列最小值都是1
思路:我们可以以行为转移的状态 附加一维限制还有多少列最小值大于1 这样我们就可以不重不漏的按照状态转移 但是复杂度确实不大行(减了两个常数卡过去的...)
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const int N = 3e5+7;
typedef long long ll;
const ll mod = 1e9+7;
using namespace std;
ll dp[300][300];
ll qpow(ll a,ll b){
ll ans=1; ll base=a;
while(b){
if(b&1) ans=ans*base%mod;
base=base*base%mod;
b>>=1;
}
return ans;
}
ll C[255][255];
int main(){
C[0][0]=1;
for(int i=1;i<=250;i++){
C[i][0]=1;
for(int j=1;j<=i;j++)C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
}
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n,k; cin>>n>>k;
for(int i=0;i<n;i++){
dp[1][i]=qpow(k-1,i)*C[n][i]%mod;
}
for(int i=2;i<=n;i++){
for(int j=0;j<n;j++){
ll x=qpow(k-1,j);
ll y=qpow(k-1,n);
for(int l=j;l<n;l++){
dp[i][j]=(dp[i][j]+dp[i-1][l]*x%mod*qpow(k,n-l)%mod*C[l][j]%mod)%mod;
if(j==l){
dp[i][j]=(dp[i][j]-y*dp[i-1][l]%mod+mod)%mod;
}
}
}
}
cout<<dp[n][0]<<endl;
return 0;
}

预处理前后差别
Codeforces Round #589 (Div. 2) Another Filling the Grid (dp)的更多相关文章
- 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 Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理
Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\) ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #589 (Div. 2)
目录 Contest Info Solutions A. Distinct Digits B. Filling the Grid C. Primes and Multiplication D. Com ...
- Codeforces Round #589 (Div. 2) (e、f没写)
https://codeforces.com/contest/1228/problem/A A. Distinct Digits 超级简单嘻嘻,给你一个l和r然后寻找一个数,这个数要满足的条件是它的每 ...
- 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 #566 (Div. 2) A. Filling Shapes
链接: https://codeforces.com/contest/1182/problem/A 题意: You have a given integer n. Find the number of ...
- Codeforces Round 589 (Div. 2) 题解
Is that a kind of fetishism? No, he is objectively a god. 见识了一把 Mcdic 究竟出题有多神. (虽然感觉还是吹过头了) 开了场 Virt ...
- Codeforces Round #589 (Div. 2) D. Complete Tripartite(染色)
链接: https://codeforces.com/contest/1228/problem/D 题意: You have a simple undirected graph consisting ...
随机推荐
- 并发编程--锁--Lock和Synchronized
说说对于 synchronized 关键字的了解? synchronized关键字解决的是多个线程之间访问资源的同步性: synchronized 关键字可以保证被它修饰的方法或者代码块在任意时刻只能 ...
- 写给小白看的Mysql事务
1 为什么需要事务 在网上的很多资料里,其实没有很好的解释为什么我们需要事务.其实我们去学习一个东西之前,还是应该了解清楚这个东西为什么有用,硬生生的去记住事务的ACID特性.各种隔离级别个人认为没有 ...
- sublime python 去掉单行超出字数的白色框框 (E501)
方法一 E501错误:行过长 (大于79个字符),在配置文件里设置 忽略E501错误即可 首选项-->Package Settings-->Anaconda-->Settings - ...
- 如何实现CentOS服务器的扩容??
Linux的硬盘识别: 一般使用"fdisk -l"命令可以列出系统中当前连接的硬盘 设备和分区信息.新硬盘没有分区信息,则只显示硬盘大小信息. 1.关闭服务器加上新硬盘 2.启动 ...
- 2021升级版微服务教程7-OpenFeign实战开发和参数调优
2021升级版SpringCloud教程从入门到实战精通「H版&alibaba&链路追踪&日志&事务&锁」 教程全目录「含视频」:https://gitee.c ...
- kubernets之卷
一 卷的由来以及种类和常用的卷的类型 前面介绍了大部分都是pod的管理以及在集群内部和集群外部如何访问pod,但是我们也了解到,pod是有生命周期的,当pod所在节点下线,或者等其他原因原因导致pod ...
- LeetCode202. 快乐数
题目 编写一个算法来判断一个数 n 是不是快乐数. 快乐数定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1, 也可能是 无限循环 但始终变不到 ...
- LeetCode349. 两个数组的交集
题目 给定两个数组,编写一个函数来计算它们的交集. 分析 数组元素值可以很大,所以不适合直接开数组进行哈希,这里要学习另一种哈希方式:集合 集合有三种,区别见下面代码随想录的Carl大佬的表格,总结的 ...
- 03--Docker 容器和镜像常用命令
一.帮助命令 docker version docker info docker --help =====================镜像命令=========================== ...
- 【分享】每个 Web 开发者在 2021 年必须拥有 15 个 VSCode 扩展
为什么VSCode如此受欢迎 Visual Studio Code在开发人员中迅速流行起来,它是最流行的开发环境,可定制性是其流行的原因之一. 因此,如果你正在使用VSCode,这里有一个扩展列表,你 ...