http://lightoj.com/volume_showproblem.php?problem=1246

题意

有个(M+1)*(N+1)的棋盘,用k种颜色给它涂色,要求曼哈顿距离为奇数的格子之间不能涂相同的颜色,每个格子都必须有颜色,问可行的方案数。

分析

经一波分析,根据曼哈顿距离为奇数这一信息,可以将棋盘分为两部分,也就是相邻格子不能有相同颜色。一种颜色只能在一个部分中出现。现在考虑对一个部分的格子操作,

dp[i][j]表示i个格子选择用了j种颜色的方案数,于是可以得到这样的递推式:dp[i][j]=dp[i-1][j-1]*j+dp[i-1][j]*j。得到dp数组后还不够,需要枚举两个部分使用的颜色数,两层循环,其中选择颜色的方案数则用组合数来算。

#include<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
#define rep(i,e) for(int i=0;i<(e);i++)
#define rep1(i,e) for(int i=1;i<=(e);i++)
#define repx(i,x,e) for(int i=(x);i<=(e);i++)
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define mset(var,val) memset(var,val,sizeof(var))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pd(a) printf("%d\n",a)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define IOS ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
template <class T>
void test(T a){cout<<a<<endl;}
template <class T,class T2>
void test(T a,T2 b){cout<<a<<" "<<b<<endl;}
template <class T,class T2,class T3>
void test(T a,T2 b,T3 c){cout<<a<<" "<<b<<" "<<c<<endl;}
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const ll mod = 1e9+;
int T;
void testcase(){
printf("Case %d: ",++T);
}
const int MAXN = 3e5+;
const int MAXM = ; ll dp[][],C[][];
void init(){
mset(C,);
for(int i=;i<;i++){
C[i][]=;
for(int j=;j<=i;j++){
C[i][j]=(C[i-][j]+C[i-][j-])%mod;
}
}
for(int i=;i<;i++){
dp[i][]=;
for(int j=;j<;j++){
dp[i][j]=(dp[i-][j]*j+dp[i-][j-]*j)%mod; }
}
} int main() {
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
init();
int t;
scd(t);
T=;
while(t--){
int m,n,k;
scddd(m,n,k);
m++,n++;
ll ans=;
if(m==n&&m==) ans=k;
else{
int n1=(n+)/*((m+)/)+n/*(m/);
int n2=m*n-n1;
for(int i=;i<k;i++){
for(int j=;i+j<=k;j++){
ans=(ans+(C[k][i]*C[k-i][j])%mod*((dp[n1][i]*dp[n2][j])%mod))%mod;
}
}
}
testcase();
cout<<ans<<endl;
}
return ;
}

LightOJ - 1246 Colorful Board(DP+组合数)的更多相关文章

  1. LightOJ - 1246 - Colorful Board(DP)

    链接: https://vjudge.net/problem/LightOJ-1246 题意: You are given a rectangular board. You are asked to ...

  2. 1246 - Colorful Board

    1246 - Colorful Board    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB ...

  3. noj 2033 一页书的书 [ dp + 组合数 ]

    传送门 一页书的书 时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte总提交 : 53            测试通过 : 1 ...

  4. 【区间dp+组合数+数学期望】Expression

    https://www.bnuoj.com/v3/contest_show.php?cid=9148#problem/I [题意] 给定n个操作数和n-1个操作符,组成一个数学式子.每次可以选择两个相 ...

  5. lightoj 1095 - Arrange the Numbers(dp+组合数)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1095 题解:其实是一道简单的组合数只要推导一下错排就行了.在这里就推导一下错排 ...

  6. hdu 3944 DP? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)

    DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0 ...

  7. Contest 20140708 testB dp 组合数

    testB 输入文件: testB.in  输出文件testB.out 时限3000ms 问题描述: 定义这样一个序列(a1,b1),(a2,b2),…,(ak,bk)如果这个序列是方序列的话必须满足 ...

  8. lightoj 1032 二进制的dp

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1032 #include <cstdio> #include <cst ...

  9. HDU 5396 Expression(DP+组合数)(详解)

    题目大意: 给你一个n然后是n个数. 然后是n-1个操作符,操作符是插入在两个数字之间的. 由于你不同的运算顺序,会产生不同的结果. 比如: 1 + 1 * 2 有两种  (1+1)*2   或者   ...

随机推荐

  1. Linux下Vim使用备忘

    1.Insert键,决定是Insert模式还是Replace模式. 2.Esc键,退出编辑模式(Insert Or Replace). 3.:wq (ZZ) 保存并退出Vim. http://caib ...

  2. Docker Dockerfile指令

    Docker 可以通过 Dockerfile 的内容来自动构建镜像.Dockerfile 是一个包含创建镜像所有命令的文本文件,通过docker build命令可以根据 Dockerfile 的内容构 ...

  3. [安全]appscan 使用代理抓取其他客户端的请求

    自己安全测试技能很低, 上级给的安全测试的任务给了自动化组的同事来做, 自己之前使用appscan的时候 只知道使用appscan的内置浏览器测试抓取请求 今天与自动化美女同事沟通发现有一个代理的功能 ...

  4. nginx的安装应用

    Nginx的安装 # yum install gcc pcre-devel zlib-devel –y #./configure –prefix=/usr/local/nginx #make & ...

  5. DevexpressVCL v51

    Dev经典套件v49版 支持Delphi2010 DevExpress公司出品的Borland Delphi和C++ Builder的控件(包含完整源代码).ExpressVerticalGrid:就 ...

  6. python之文件系统操作(os模块)

    文件系统操作(os模块) import os file_name = "D:\\test_data\\1.txt" file_name_2 = "D:\\test_dat ...

  7. Lodop不要把客户端的打印机共享到服务器上 再在客户端打印

    客户端打印需要每个客户端都安装,Lodop插件方式和C-Lodop方式,都是安装一次后,无需再次安装,c-lodop默认也是开机自启动的.集中打印方式,可以打印到某台电脑(作为云主机)上,但是不能打印 ...

  8. asp.net 后台<%@ Page%> page指令属性

    aspx文件有如下一行代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind=" ...

  9. pgm13

    这部分开始,我们将讨论 learning 相关的内容.PGM 为 frequentist 与 Bayesian 系的 model 提供了同一种语言,对前者来说 learning 就是确定一种对“未知但 ...

  10. BZOJ1093 ZJOI2007最大半连通子图(缩点+dp)

    发现所谓半连通子图就是缩点后的一条链之后就是个模板题了.注意缩点后的重边.写了1h+真是没什么救了. #include<iostream> #include<cstdio> # ...