Codeforces #144 (Div. 1) B. Table (组合数学+dp)
题目链接:
B.Table
题意:
\(n*m\)的矩阵使每个\(n*n\)矩阵里面准确包含\(k\)个点,问你有多少种放法。
\((1 ≤ n ≤ 100; n ≤ m ≤ 10^{18}; 0 ≤ k ≤ n^2)\)
题解:
- Let \(s_i\) number of points in the column \(i\).
- Two neighboring squares are drawn at this picture, \(A\) is the number of point it the left area (it is one column), \(B\) is the number of points in the middle area and \(C\) is the number of points in the right area (it is one column too). That's why by definition we ###have:
- Therefore \(A = C\).
- That's why 
- Divide all columns by equivalence classes on the basis of \(i \mod n\) . For all \(a\) and \(b\) from one class \(s_a = s_b\).
cnta is number of columns in class with 
- There are \(C(n,k)^{cnt_a}\) ways to draw \(k\) points in the each of columns in the class \(a\) independendently of the other classes.
- \(dp[i][j]\) is number of ways to fill all columns in classes \(1, ... i\) in such way that .
- \(cnt_i\) take only two values
and 
. Let's calc \(C(n,a)^{cnt_i}\) for all \(a\) and \(cnt_i\) and use it to calc our dp. We have \(O(n^2·k)\) complexity.
代码:
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
const int N = 123;
const int K = 10000+1230;
ll pow1[N],pow2[N];
ll dp[N][K];
ll c[N][N];
//n*m的矩阵使每个n*n矩阵里面准确包含k个点,问你有多少种放法。
ll quick_pow(ll a,ll b)
{
ll tmp=a;
ll ans=1;
while(b)
{
if(b&1) ans=(ans*tmp)%mod;
tmp=(tmp*tmp)%mod;
b>>=1;
}
return ans;
}
int main()
{
int n,k;
ll m;
cin>>n>>m>>k;
for(int i=0;i<=n;i++) c[i][0]=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
}
}
for(int i=0;i<=n;i++)
{
pow1[i]=quick_pow(c[n][i],m/n);
pow2[i]=(pow1[i]*c[n][i])%mod;
}
dp[0][0]=1;
ll now;
for(int i=0;i<n;i++)
{
for(int j=0;j<=k;j++)
{
if(dp[i][j]!=0)
{
for(int p = 0;p <= n && j + p <= k;p++)
{
if(i<m%n) now=pow2[p];
else now=pow1[p];
dp[i+1][j+p]=(dp[i+1][j+p]+dp[i][j]*now)%mod;
}
}
}
}
cout<<dp[n][k]<<endl;
return 0;
}
Codeforces #144 (Div. 1) B. Table (组合数学+dp)的更多相关文章
- Codeforces Round #345 (Div. 1) C. Table Compression dp+并查集
题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secon ...
- Codeforces Round #144 (Div. 2) D table
CodeForces - 233D 题目大意给你一个n*m 的矩阵,要求你进行涂色,保证每个n*n的矩阵内都有k个点被涂色. 问你一共有多少种涂色方案. n<=100 && m& ...
- Codeforces Gym 100338H High Speed Trains 组合数学+dp+高精度
原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...
- codeforces 869C The Intriguing Obsession【组合数学+dp+第二类斯特林公式】
C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...
- 贪心 Codeforces Round #273 (Div. 2) C. Table Decorations
题目传送门 /* 贪心:排序后,当a[3] > 2 * (a[1] + a[2]), 可以最多的2个,其他的都是1个,ggr,ggb, ggr... ans = a[1] + a[2]; 或先2 ...
- Codeforces #345 Div.1
Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...
- [CodeForces - 1272D] Remove One Element 【线性dp】
[CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Me ...
- 让div中的table居中
div 标签上写 style="text-align:center" div中的table中写 style="margin:auto;" <table ...
- Codeforces 219D. Choosing Capital for Treeland (树dp)
题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:10240000 ...
随机推荐
- ios程序启动过程和UIWidnow介绍
一.iOS程序的完整启动过程(有storyboard) 1.先执行main函数,main内部会调用UIApplicationMain函数 2.UIApplicationMain函数里面做了什么事情: ...
- 洛谷——P1043 数字游戏
https://www.luogu.org/problem/show?pid=1043 题目描述 丁丁最近沉迷于一个数字游戏之中.这个游戏看似简单,但丁丁在研究了许多天之后却发觉原来在简单的规则下想要 ...
- 洛谷 P3585 [POI2015]PIE
P3585 [POI2015]PIE 题目描述 一张n*m的方格纸,有些格子需要印成黑色,剩下的格子需要保留白色.你有一个a*b的印章,有些格子是凸起(会沾上墨水)的.你需要判断能否用这个印章印出纸上 ...
- TaoCode-淘宝的SVN开源托管平台
无意中发现的..试用了一下,感觉还不错, 简单说一下怎样使用: 进入 http://code.taobao.org/project/explore/ 注冊完后依据提示新建项目,然后在本地随便新建一个文 ...
- zoj 2778 - Triangular N-Queens Problem
题目:在三角形的棋盘上放n皇后问题. 分析:找规律题目.依照题目的输出,能够看出构造法则: 先填奇数,后填偶数.以下我们仅仅要证明这样的构造的存在性就可以. 解法:先给出集体构造方法,从(1.n-f( ...
- Vue绑定事件
<!-- 方法处理器 --> <button v-on:click="doThis"></button> <!-- 内联语句 --> ...
- 11.Axis客户端接收不同参数类型
转自:http://www.guance.com/708.html axis只支持简单类型的返回值.在这里逐一介绍axis的各种返回值接受. 1. axis接受基本类型,如int, string等 引 ...
- 【习题 8-14 UVA - 1616】Caravan Robbers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 二分长度. 显然长度越长.就越不可能. 二分的时候.可以不用管精度. 直接指定一个二分次数的上限就好. 判断长度是否可行.直接用贪心 ...
- 使用框架的php假设使用定时服务Cronjob
工作须要用php开发了个监控的小程序,既然是监控就须要定时运行. 之前我用的是chrome加个定时刷新的小插件,放在server上执行.也能实现,就是别扭. 通用正规的做法应该是:linux上的Cro ...
- 深入理解javascript之原型
理解原型 原型是一个对象.其它对象能够通过它实现属性继承. 不论什么一个对象都能够成为继承,全部对象在默认的情况下都有一个原型.由于原型本身也是对象,所以每一个原型自身又有一个原型. 不论什么一个对象 ...