Codeforces Round #144 (Div. 2) D table
题目大意给你一个n*m 的矩阵,要求你进行涂色,保证每个n*n的矩阵内都有k个点被涂色。
问你一共有多少种涂色方案。 n<=100 && m<=1e18
看数据范围感觉是个矩阵快速幂优化的dp,各种想,连状态转移方程都想不出来,我真
鸡儿菜!!!!,这种和概率有关的dp我感觉好蓝啊!!!
思路:显然是个dp,我们另dp[ i ][ j ]表示,到 i 列,一共涂了j个格子的种数,
那么有状态转移方程 dp[ i ][ j ] +=Σ(dp[ i - 1 ][ j - s ] * c[ n ][ s ] ) ( 0<=s<=j ) c[ i ] [ j ]表示组合数。
但是m的范围是1e18显然不能直接dp,我们观察可以发现,第 i 列 和 第 i + n 列的涂色格子的
个数肯定是一样的,那么我们可以用快速幂把>n的列的种数全部并到<n 的列中,这样就能在
100^3的时间内完成。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+;
ll c[][],n,m,k,dp[][],res[][][];
void init()
{
c[][]=;
for(int i=;i<=;i++)
{
c[i][]=i;
c[i][i]=c[i][]=;
for(int j=;j<i;j++)
{
c[i][j]=(c[i-][j-]+c[i-][j])%mod;
}
}
}
ll q_pow(ll x,ll k)
{
ll ans=,d=x;
while(k)
{
if(k&) ans=(ans*d)%mod;
d=(d*d)%mod;
k>>=;
}
return ans;
}
int main()
{
init();
cin>>n>>m>>k;
int r=m%n;
for(int i=;i<=n;i++)
{
for(int j=;j<=k;j++)
{
if(j>n) break;
if(i<=r) res[i][j][]=q_pow(c[n][j],m/n+);
else res[i][j][]=q_pow(c[n][j],m/n);
}
}
for(int i=;i<=n;i++) dp[i][]=;
for(int i=;i<=n;i++)
{
for(int j=;j<=k;j++)
{
for(int u=;u<=min((ll)j,n);u++)
{
if(i<=r) dp[i][j]=(dp[i][j]+dp[i-][j-u]*res[i][u][])%mod;
else dp[i][j]=(dp[i][j]+dp[i-][j-u]*res[i][u][])%mod;
}
}
}
printf("%I64d\n",dp[n][k]);
return ;
}
Codeforces Round #144 (Div. 2) D table的更多相关文章
- 贪心 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 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 #345 (Div. 2) E. Table Compression 并查集
E. Table Compression 题目连接: http://www.codeforces.com/contest/651/problem/E Description Little Petya ...
- Codeforces Round #273 (Div. 2)-C. Table Decorations
http://codeforces.com/contest/478/problem/C C. Table Decorations time limit per test 1 second memory ...
- Codeforces Round #144 (Div. 2)
A. Perfect Permutation 奇偶对调. B. Non-square Equation \(s(x)\)不超过200,根据求根公式计算\(x\). C. Cycles 每次新增点时都和 ...
- codeforces Codeforces Round #345 (Div. 1) C. Table Compression 排序+并查集
C. Table Compression Little Petya is now fond of data compression algorithms. He has already studied ...
- codeforces 的 Codeforces Round #273 (Div. 2) --C Table Decorations
C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #273 (Div. 2)C. Table Decorations 数学
C. Table Decorations You have r red, g green and b blue balloons. To decorate a single table for t ...
- Codeforces Round #345 (Div. 2) E. Table Compression 并查集+智商题
E. Table Compression time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- ext中grid根据数据不同显示不同样式
核心代码: var clsRender = function(value){ if (value == 'male') { return "<span style='color:red ...
- Bugly实现app全量更新
转 http://blog.csdn.net/qq_33689414/article/details/54911895Bugly实现app全量更新 Bugly官网文档 一.参数配置 在app下的gra ...
- APR欺骗
ARP欺骗简介 ARP欺骗是一种在局域网中常用的攻击手段,目的是让局域网中指定的(或全部)的目标机器的数据包都通过攻击者主机进行转发,是实现中间人攻击的常用手段,从而实现数据监听.篡改.重放.钓鱼等攻 ...
- 让 IE9 以下的浏览器支持 Media Queries
1. 如何让 IE9 以下的浏览器支持 css3 的media query 需要用到的 min-width/max-width 属性 css3 的媒体查询 IE 浏览器的支持程度是从 IE9开始支持, ...
- stderr 和stdout
今天又查了一下fprintf,其中对第一个参数stderr特别感兴趣. int fprintf(FILE *stream,char *format,[argument]): 在此之前先区分一下:pri ...
- Dubbo监控中心
(1).dubbo-admin(管理控制台) 1).从https://github.com/apache/incubator-dubbo-ops下载解压 2).修改dubbo-admin配置文件中zo ...
- 使用python中的matplotlib 画图,show后关闭窗口,继续运行命令
使用python中的matplotlib 画图,show后关闭窗口,继续运行命令 在用python中的matplotlib 画图时,show()函数总是要放在最后,且它阻止命令继续往下运行,直到1.0 ...
- b站评论爬取
var userData = {}; var startPage = 0; var endPage = 0; var startTime = ""; var endTime = & ...
- gunicorn+flask使用与配置
gun.conf的内容 import os bind = '10.1.240.222:5000' workers = 4 backlog = 2048 worker_class = "syn ...
- Project Euler Problem7
10001st prime Problem 7 By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see t ...