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. Java Configuration Manager Automatic Reloading

    公司一个项目的从另外一个小公司,拷贝了一个PropertyParser的类,实现的有问题,必须重启java应用才能读取新的配置. 简单的解决办法,就是每次读任何配置项时,都重新加载xxx.proper ...

  2. Centos7搭建LAMP+Typecho博客

    一.安装Apache的httpd服务 yum install httpd # 安装httpd服务 systemctl start httpd # 启动httpd服务 systemctl status ...

  3. iphone 与 PC端电脑投屏设置

    1. iphone端安装: 屏幕投影助手 下载地址 https://itunes.apple.com/cn/app/ping-mu-tou-ying-zhu-shou/id1152332174?mt= ...

  4. loadrunner基础学习笔记五-场景

    场景目标:模拟10家旅行社同时登录.搜索航班.购买机票.查看航班路线并退出 负载测试是指在典型工作条件下测试应用程序,例如:多家旅行社同时在同一个机票预订系统中预订机票 controller提供所有用 ...

  5. js 消息框

    消息框有三種:警告框.提示框.確認框 警告框: 確保用戶可以得到某些信息. 點擊確定以後,才能繼續後續操作. alert("不好") 確認框: 請用戶確認或者接受某些信息. 點擊確 ...

  6. Java之map使用方法

    package basic; import java.util.HashMap; import java.util.Map; //map使用方法 public class MapDemo { publ ...

  7. POI 生成excel(大数据量) SXSSF

    使用POI 的SXSSF (Streaming Usermodel API)生成较大的excel,同时开启压缩 import junit.framework.Assert; import org.ap ...

  8. JVM 内存区域 (运行时数据区域)

    JVM 内存区域 (运行时数据区域) 链接:https://www.jianshu.com/p/ec479baf4d06 运行时数据区域 Java 虚拟机在执行 Java 程序的过程中会把它所管理的内 ...

  9. Twitter数据挖掘:如何使用Python分析大数据 (3)

    让我们来拉取Twitter账号@NyTimes的最近20条微博. 我们可以创建变量来存放待拉取的微博数量(即count),以及待拉取的用户(即name).然后用这两个参数调用user_timeline ...

  10. 自学Linux Shell16.1-函数概念

    点击返回 自学Linux命令行与Shell脚本之路 16.1-函数概念 编写比较复杂的shell脚本时,完成具体任务的代码可能需要重复使用.bash shell提供满足这种要求的特性.函数是被赋予名称 ...