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. 使用java.util.LinkedList模拟实现内存页面置换算法--LRU算法

    一,LRU算法介绍 LRU是内存分配中“离散分配方式”之分页存储管理方式中用到的一个算法.每个进程都有自己的页表,进程只将自己的一部分页面加载到内存的物理块中,当进程在运行过程中,发现某页面不在物理内 ...

  2. FASTREPORT COM/ActiveX报表如何保存到C++项目中?

    可以的. VC++ : ... IStream * pStream;CreateStreamOnHGlobal(NULL, true, &pStream);pStream->AddRef ...

  3. 《深入理解java虚拟机》第三章 垃圾收集器与内存分配策略

    第三章 垃圾收集器与内存分配策略 3.1 概述 哪些内存需要回收 何时回收 如何回收 程序计数器.虚拟机栈.本地方法栈3个区域随线程而生灭. java堆和方法区的内存需要回收.   3.2 对象已死吗 ...

  4. Postfix 邮件服务 - DNS服务

    DNS 服务 (系统需要配置静态 IP 地址) yum install bing* -y 一.配置 NDS 域名解析: 直接添加以下内容: [root@mail ~]# cat /etc/named. ...

  5. MSSQL-SELECT&UPDATE动作要申请的锁

    最近在学习[MySQL事务&锁]这块知识,一不留神和MSSQL乱窜了~.~ 文章最初是想查看MySQL vs MSSQL在下面环境产生的阻塞现象会话1开启事务更新数据尚未提交->会话2读 ...

  6. slf4j的简单用法以及与log4j的区别

    之前在项目中用的日志记录器都是log4j的日志记录器,可是到了新公司发现都是slf4j,于是想着研究一下slf4j的用法. 注意:每次引入Logger的时候注意引入的jar包,因为有Logger的包太 ...

  7. POI导出Excel(xls、xlsx均可以,也支持图片)——(三)

    Jar包

  8. ARMV8 datasheet学习笔记2:概述

    1. 前言 本文主要概括的介绍ARMV8体系结构定义了哪些内容,概括的说: ARM体系结构定义了PE的行为,不会定义具体的实现 ARM体系结构也定义了debug体系结构和trace体系结构 ARM体系 ...

  9. WIN10 ISO 官方

    WIN10   ISO  官方: https://www.microsoft.com/zh-cn/software-download/windows10ISO/

  10. spring上传文件

    在使用spring上传文件的时候,使用的文件接收参数类型为 org.springframework.web.multipart.MultipartFile 如果该参数没有指定@RequestParam ...