CodeForces - 233D

题目大意给你一个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的更多相关文章

  1. 贪心 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 ...

  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 ...

  3. Codeforces Round #345 (Div. 2) E. Table Compression 并查集

    E. Table Compression 题目连接: http://www.codeforces.com/contest/651/problem/E Description Little Petya ...

  4. 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 ...

  5. Codeforces Round #144 (Div. 2)

    A. Perfect Permutation 奇偶对调. B. Non-square Equation \(s(x)\)不超过200,根据求根公式计算\(x\). C. Cycles 每次新增点时都和 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. mips体系堆栈回溯分析与实现

    转载:http://www.sohu.com/a/118385096_468740 mips栈帧原理 Call stack 是指存放某个程序的正在运行的函数的信息的栈.Call stack 由 sta ...

  2. TCP 链接 存在大量 close_wait 等待

    大量 close_wait 等待 调整linux下 /etc/sysctl.conf参数,里面设置参数: # net.ipv4.tcp_keepalive_time 然后执行 # sysctl -p

  3. luogu P3674 小清新人渣的本愿

    传送门 毒瘤lxl 本质是莫队,关键是怎么处理询问 这里需要开两个bitset(记为\(b1,b2\)),分别存\(x\)和\(n-x\)是否出现 对于询问1,即\(x-y=z\),由于\(y=x-z ...

  4. html 替换元素

    参考博客:http://www.cnblogs.com/wkylin/archive/2011/05/12/2044328.html 可替换元素也是行内元素 替换元素是浏览器根据其标签的元素与属性来判 ...

  5. python 错误--UnboundLocalError: local variable '**' referenced before assignment

    val = 9 def test(flag): if flag: val = 1 else: print("test") return val if __name__ == '__ ...

  6. 一步一步详解ID3和C4.5的C++实现

    1. 关于ID3和C4.5的原理介绍这里不赘述,网上到处都是,可以下载讲义c9641_c001.pdf或者参考李航的<统计学习方法>. 2. 数据与数据处理 本文采用下面的训练数据: 数据 ...

  7. SpringBoot集成监控管理

    (1).添加starter依赖 <dependency> <groupId>org.springframework.boot</groupId> <artif ...

  8. Python Tools for Machine Learning

    Python Tools for Machine Learning Python is one of the best programming languages out there, with an ...

  9. 命令行command line 使用 http proxy的设置方法 Setting Up HTTP Proxy in Terminal

    Step 1: Install Shadowsocks Client Shadowsocks is an open-source proxy project to help people visit ...

  10. 工作中bug笔记

    1.报Cannot read property  indexOf of undefined 错误的时候!!!报这种错的时候,一般是因为indexOf前面检查的东西是不存在的!!!!!  2.使用< ...