HDU 4363
这题是记忆化搜索很容易想到,但状态却不好设
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的更多相关文章
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
- hdu 4329
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟 a. p(r)= R'/i rel(r)=(1||0) R ...
随机推荐
- ARM VM安装Linux Diagnostic 2.3扩展
目前创建的Azure Linux虚拟机默认安装的是LAD 3.0,如果客户有特殊需求,可以通过如下方法安装LAD 2.3 1.在Azure Portal卸载LAD 3.0 2.使用Azure Powe ...
- golang——常用内建函数
(1)func len(v Type) int 返回长度,取决于具体类型:字符串返回字节数:channel返回缓存元素的个数: (2)func cap(v Type) int 返回容量,取决于具体类型 ...
- 巴什博弈------最少取件数 不是1的情况下 hdu---2897
最少取件数 是1的时候 核心代码是 // 共有 n 见 物品 一次最少取 一个 最多取 m 个 )==) printf("先取者输"); 在代码中 可以看到 题目中 一共 ...
- 为什么使用HttpServlet?http协议特点、servlet
因为只有HttpServlet是基于http协议,实现Servlet接口,而http协议是短连接协议,能够实现客户端访问服务端后,数据交互后 连接自动断开.同时http协议基于tcp.ip协议,封装了 ...
- [转]linux之diff 命令
转自:http://www.cnblogs.com/peida/archive/2012/12/12/2814048.html diff 命令是 linux上非常重要的工具,用于比较文件的内容,特别是 ...
- 【转】Linux下变量内容删除与替换
转自:http://www.linuxidc.com/Linux/2015-01/111781.htm 当一个变量被赋予值后,有时会对变量的值进行一些微小的调整,比如删除变量值中特定一部份,或替换掉一 ...
- win7 硬盘安装suse双系统启动顺序更改
使用win7硬盘安装suse双系统之后,首先面临的问题是,PC默认启动的系统更改的问题,有些人可能想默认启动是win7,只有在使用linux的时候在去选择suse系统,这里我告诉大家更改的办法: 首先 ...
- oracle for linux服务器磁盘空间不足,通过过期的文件释放磁盘空间
--2013-09-16截取的数据-- 使用df-h命令查看系统磁盘空间 [root@erpdbs PROD]# df -h Filesystem Size Used Avail Use% Mount ...
- 使用jquery animate实现锚点慢慢平滑滚动效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- html5——拖拽
基本情况 在HTML5的规范中,我们可以通过为元素增加draggable="true"来设置此元素是否可以进行拖拽操作,其中图片.链接默认是开启的. 拖拽元素 页面中设置了drag ...