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 ...
随机推荐
- ubuntu16.04更改源
最近用apt-get安装软件总是提示列表无法全部更新,导致一些软件安装不上,下面我们通过讲/etc/apt/sources.list里为阿里源,实现访问. 第一步: 备份/etc/apt/source ...
- Akka源码分析-Actor创建
上一篇博客我们介绍了ActorSystem的创建过程,下面我们就研究一下actor的创建过程. val system = ActorSystem("firstActorSystem" ...
- Springboot2.0部署阿里云服务器(nginx+域名+SSL)供Http和Https访问
总算是弄出来了,先写下来供自己以后查阅. 1)首先你要有一个阿里云服务器,我用的是Centos7学生认证,10元/月,很便宜也很好用. 2)购买了域名,首年9元,很划算.域名买来之后经历了拍照备案,前 ...
- HTML--使用提交按钮,提交数据
在表单中有两种按钮可以使用,分别为:提交按钮.重置.这一小节讲解提交按钮:当用户需要提交表单信息到服务器时,需要用到提交按钮. 语法: <input type="submit" ...
- Java——Spring注解
Spring常用注解使用注解来构造IoC容器用注解来向Spring容器注册Bean.需要在applicationContext.xml中注册<context:component-scan bas ...
- JavaScript 封装插件学习笔记(一)
此篇只是笔记,在借鉴.参考.模仿的过程,可能不完整,请多指教! 定义插件名称要注意命名冲突,防止全局污染. 1.第一种Javascript对象命名:(Javascript语言是“先解析,后运行”,解析 ...
- [Android]有关外部链接唤醒App需要注意的坑
移动互联网发展到今天,一个移动app需要和各种各样的外部链接关联,它不再仅仅从手机的桌面启动,更多的将会从其他的应用.浏览器链接.短信.二维码或者微信分享等渠道启动,这里涉及到的是各种各样的营销渠道和 ...
- Alpha Edition [ Group 1 ]
Deltafish Alpha Edition 一.博客归档(记录人:娄雨禛) 小组会议 DeltaFish 校园物资共享平台 第一次小组会议 DeltaFish 校园物资共享平台 第二次小组会议 D ...
- xml操作-Nested exception: org.xml.sax.SAXParseException: White spaces are required between publicId and systemId. 异常处理
异常如下: org.dom4j.DocumentException: Error on line 2 of document file:///D:/workspaces/struts2/lesson0 ...
- 如何快速获取yun2win app key?
注册yun2win开发者账号 1.在注册页面输入您的邮箱,点击下方发送,yun2win将会发送一封验证邮件到您的邮箱: 2.如果没有收到邮件请查看垃圾箱或者点击重新发送: 3.打开邮箱查看验证邮件,点 ...