这题是记忆化搜索很容易想到,但状态却不好设

dp[i][j][u][d][l][r][k]。对于矩形为i*j,它的四周的颜色分别为u,d,l,r,横竖切的状态为k的种数。

其中要注意一个问题是,停止不一定是不可进行,而是随时都可以停止,这样就会有一种涂色为对某个矩形而言只涂一种颜色。那么,就必定会有重复的上下矩形只涂两种颜色的重复出现,这样就要减去这些重复的。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL __int64
using namespace std ;
const LL MOD=1000000007;
LL dp[42][42][5][5][5][5][2]; void dfs(int i,int j,int u,int d,int l,int r,int w){
if(dp[i][j][u][d][l][r][w]!=-1) return ;
LL ret=0;
for(int c=1;c<=4;c++){
if(c!=u&&c!=d&&c!=l&&c!=r) ret++;
}
if(w==1){
for(int h=1;h<i;h++){
for(int c=1;c<=4;c++){
if(c!=u&&c!=l&&c!=r){
dfs(i-h,j,c,d,l,r,0);
ret=(ret+dp[i-h][j][c][d][l][r][0])%MOD;
}
}
for(int c=1;c<=4;c++){
if(c!=d&&c!=l&&c!=r){
dfs(h,j,u,c,l,r,0);
ret=(ret+dp[h][j][u][c][l][r][0])%MOD;
}
}
}
LL counts=0;
for(int c1=1;c1<=4;c1++){
if(c1!=u&&c1!=l&&c1!=r){
for(int c2=1;c2<=4;c2++){
if(c2!=l&&c2!=r&&c2!=c1&&c2!=d)
counts++;
}
}
}
counts=counts*(i-1);
ret=((ret-counts)%MOD+MOD)%MOD;
}
else{
for(int k=1;k<j;k++){
for(int c=1;c<=4;c++){
if(c!=u&&c!=l&&c!=d){
dfs(i,j-k,u,d,c,r,1);
ret=(ret+dp[i][j-k][u][d][c][r][1])%MOD;
}
}
for(int c=1;c<=4;c++){
if(c!=u&&c!=r&&c!=d){
dfs(i,k,u,d,l,c,1);
ret=(ret+dp[i][k][u][d][l][c][1])%MOD;
}
}
}
LL counts=0;
for(int c1=1;c1<=4;c1++){
if(c1!=u&&c1!=l&&c1!=d){
for(int c2=1;c2<=4;c2++){
if(c2!=c1&&c2!=r&&c2!=u&&c2!=d)
counts++;
}
}
}
counts=counts*(j-1);
ret=((ret-counts)%MOD+MOD)%MOD;
}
dp[i][j][u][d][l][r][w]=ret;
} int main(){
memset(dp,-1,sizeof(dp));
int T,n,m;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
dfs(n,m,0,0,0,0,1);
printf("%I64d\n",dp[n][m][0][0][0][0][1]);
}
return 0;
}

  

写的时候要特别小心,很容易出现BUG。调了我一晚上。

HDU 4363的更多相关文章

  1. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  3. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  4. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  6. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  7. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

  9. hdu 4329

    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R ...

随机推荐

  1. VUE移动端禁止双手放大缩小

    //index.html <meta name="viewport" content="width=device-width,initial-scale=1.0,u ...

  2. centos语言设置

    . echo $LANG可以查看当前使用的系统语言 . 在终端输入 locale命令,如有zh cn 表示已经安装了中文 . 安装中文语言包yum groupinstall chinese-suppo ...

  3. ZOJ1969-Hard to Believe, but True!

    import re while True: x = raw_input() if(x == '0+0=0'): print 'True' break a,b,c = re.split('[+=]', ...

  4. NS2学习笔记(一)

    NS2有两种运行方式: 1.“脚本方式”,输入命令: ns tclscripl.tcl,其中 tclscripl.tcl 是一个Tcl脚本的文件名: 2“命令行方式”,输入命令:ns,进入NS2的命令 ...

  5. ansible剧本

    yaml简介 YAML是"YAML Ain't a Markup Language"(YAML不是一种置标语言)的递归缩写,早先YAML的意思其实是:"Yet Anoth ...

  6. android 蓝牙 通信 bluetooth

    此例子基于 android demo Android的蓝牙开发,虽然不多用,但有时还是会用到,  Android对于蓝牙开发从2.0版本的sdk才开始支持,而且模拟器不支持,测试需要两部手机:     ...

  7. body全屏css/网页全屏设置/全屏样式

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. 联想 K10(K10e70) 免解锁BL 免rec Magisk Xposed 救砖 ROOT 版本号 S206

    >>>重点介绍<<< 第一:本刷机包可卡刷可线刷,刷机包比较大的原因是采用同时兼容卡刷和线刷的格式,所以比较大第二:[卡刷方法]卡刷不要解压刷机包,直接传入手机后用 ...

  9. jQuery制作顶部与左侧锚点板块定位功能带动画跳转特效

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. vue中使用Swiper

    第一步:安装swiper在项目目录下打开命令窗口输入命令:npm install swiper 第二步:引入js文件 第三步:引入css文件在main.js文件中引入css文件