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 ...
随机推荐
- 淘淘商城之SSM框架整合概要
一.后台系统所用的技术 1)框架:Spring + SpringMVC + Mybatis: 2)前端:EasyUI: 3)数据库:mysql 二.创建数据库 1)安装mysql数据库: 2)在mys ...
- Javaweb学习笔记——(二)——————CSS概述,进入JavaScript
day02day01内容回顾 1.html操作思想 **使用标签把要操作的数据包起来,通过修改标签的属性值来是实现标签内数据样式的变化 ***<font size="5"&g ...
- ASP.NET MVC中的Session设置
最近在ASP.NET MVC项目中碰到这样的情况:在一个controller中设置了Session,但在另一个controller的构造函数中无法获取该Session,会报"System.N ...
- day1 查看当前目录命令:pwd
用到查看当前目录的完整路径使用:pwd 物理路径和连接路径什么鬼?没明白暂时借鉴别人的记录下 显示当前目录的物理路径 pwd –P 1: [root@DB-Server init.d]# cd /et ...
- python - 上下文管理协议(with + __enter__ + __exit__)
上下文管理协议: with + __enter__ + __exit__ #上下问管理协议: #with + __enter__ + __exit__ class Test(): def __init ...
- Java并发编程(1)-Java内存模型
本文主要是学习Java内存模型的笔记以及加上自己的一些案例分享,如有错误之处请指出. 一 Java内存模型的基础 1.并发编程模型的两个问题 在并发编程中,需要了解并会处理这两个关键问题: 1.1.线 ...
- Web下文件上传下载的路径问题
工程结构
- sum行列合计
select sum(decode(cplb,'3',hj,0)) from lr_scsjdqdw t group by zcxmdm
- art 校准时设备端操作
(1)准备所需文件art.ko 和 nart.out (2)配置设备的IP地址(例如:192.168.2.122),使之能与本地PC通信 (3)上传文件到设备 cd /tmp tftp -g -r ...
- 玩树莓派(raspberry pi) 2/3 raspbian的遇到的一些问题
raspberry pi买回来玩了一段时间,现在就记录一下入门遇到的一些问题吧. 首先是烧写镜像,和安装电脑系统是一样的道理. 先要有一个制作一个U启动盘.先将SD卡格式化,再用Win32DiskIm ...