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 ...
随机推荐
- 【Codeforces Round #460 (Div. 2) A】 Supermarket
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 就是让你求m*(ai/bb)的最小值 [代码] #include <bits/stdc++.h> #define dou ...
- 关于Shiro的退出请求是如何关联到登录请求的思考
一.结论 先给出结论,是因为本身是很简单的道理.假设我们没有使用任何认证授权的框架,就简单的使用Cookie和HttpSession,那么用户登录后的每一个请求是如何关联上这个用户的呢?答案很简单,由 ...
- Cocos2D实现RPG队伍菜单随意调整角色顺序的效果
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 假设认为写的不好请多提意见,假设认为不错请多多支持点赞.谢谢! hopy ;) 前一篇我们实现了队伍实现拖尾效果,可是在实际游戏中我们往往须要 ...
- julia/pyplot 绘图加入标签和标题
julia 调用matplotlib.pyplot 须要先using pycall 先安装pycall Pkg.add("PyCall") 然后吧. . . 上代码把:(应该是通俗 ...
- Onvif开发之客户端鉴权获取参数篇
前面一篇已经介绍了客户端如何发些设备,下面这篇简单介绍下在发现设备后,如何通过ONVIF协议来获取设备的相关参数 ONVIF中不管是客户端还是设备端,最先实现的接口都是关于能力的那个接口,在客户端实现 ...
- 什么是CSS重置,有些什么作用?
CSS重置是什么? 简单的说就是重置浏览器的CSS默认属性. 为什么要重置它,有什么作用? 因为浏览器的品种很多,每个浏览器的默认样式也是不同的,比如<button>标签,在IE浏览器.F ...
- 给iOS项目中添加图片,并通过UIImageView引用和显示该UIImage图片
[问题] 关于iOS/iPhone中的文件选择对话框,用于用户去选择图片等文件 过程中,问题转换为,需要给当前iOS项目中,添加一个图片. 类似于Windows开发中的资源文件,其中图片文件属于资源的 ...
- Shiro + SSM(框架) + Freemarker(jsp)
Shiro + SSM(框架) + Freemarker(jsp)讲解的权限控制Demo,还不赶快去下载? 我们知道Ajax不能做页面redirect和forward跳转,所以Ajax请求假如没登录, ...
- coverage python 代码覆盖率工具使用(django 使用)
1. 安装包 pip install coverage 2.启动程序 coverage run -m pytest 3.获取html格式的报告文件 coverage html 4.创建配置文件 .co ...
- Java中的继承和接口
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 这是个老话题,继承和接口是实现多态的两种方式,如果对象很多,其中一对一对的有共同点,建议用继承,如果 ...


