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 ...
随机推荐
- ZOJ 2562 HDU 4228 反素数
反素数: 对于不论什么正整数x,起约数的个数记做g(x).比如g(1)=1,g(6)=4. 假设某个正整数x满足:对于随意i(0<i<x),都有g(i)<g(x),则称x为反素数. ...
- Json数据的序列化与反序列化的三种经常用法介绍
下面内容是本作者从官网中看对应的教程后所做的demo.其体现了作者对相关知识点的个人理解..作者才疏学浅,难免会有理解不到位的地方.. 还请各位读者批判性对待... 本文主要介绍在Json数据的序列化 ...
- 手动脱FSG壳实战
作者:Fly2015 对于FSG壳.之前没有接触过是第一次接触.这次拿来脱壳的程序仍然是吾爱破解论坛破解培训的作业3的程序.对于这个壳折腾了一会儿,后来还是被搞定了. 1.查壳 首先对该程序(吾爱破解 ...
- 用ElasticSearch,LogStash,Kibana搭建实时日志收集系统
用ElasticSearch,LogStash,Kibana搭建实时日志收集系统 介绍 这套系统,logstash负责收集处理日志文件内容存储到elasticsearch搜索引擎数据库中.kibana ...
- 洛谷P1720 月落乌啼算钱
目背景 (本道题目木有以藏歌曲……不用猜了……) <爱与愁的故事第一弹·heartache>最终章. 吃完pizza,月落乌啼知道超出自己的预算了.为了不在爱与愁大神面前献丑,只好还是硬着 ...
- SQL 金额添加千分位
SELECT CONVERT(NVARCHAR(50),CAST(1000000 AS MONEY),1) SELECT CONVERT(NVARCHAR,CAST(1343432432434.8 A ...
- 搭建 Nginx 静态网站
示例代码:/etc/nginx/nginx.conf user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid / ...
- Web开发中,使用表格来展示每个角色对应的权限
通过表格这种方式,来展示角色和权限之间的关系,挺好的.还有很多场景,都可以用这种方式. 角色权限表 权限 系统管理员 文章管理员 相册管理员 留言管理员 个人信息管理 查看个人信息 √ √ √ √ 编 ...
- Codeforces Round #316 (Div. 2) A B C
A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Log4j日志管理的简单实例
大型项目中非常多情况下要分析程序的日志信息,怎样管理自己的日志信息至关重要. 在应用程序中加入日志记录总的来说基于三个目的 , 监视代码中变量的变化情况,周期性的记录到文件里供其它应用进行统计分析工作 ...