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 ...
随机推荐
- Python基础数据类型(三)list 列表
3.4列表list [] 列表的格式 lst_l = [1,'123',[1,'www',2],'包青天'] 列表也有索引 print(lst_l[0]) print([-1][0:2]) #包青 切 ...
- ACM_Mystery
Mystery Time Limit: 2000/1000ms (Java/Others) Problem Description: No Description Input: The first l ...
- Patch 21352635 - Database Patch Set Update 11.2.0.4.8
一.CPU和PSU 近日,将数据库从9.2.0.6升级到11.2.0.4后,发现11.2.0.4通过DBLINK访问其他的9i库时发生ORA-02072错误,通过Google找到解决方案,即升级到PS ...
- SQL Sever语言 事务
事务:保障流程的完整执行保证程序某些程序在运行时同时成功同时失败,保证程序的安全性 begin tran --在流程开始的位置加 --此处写SQL语句 if @@error>0 --ERRORS ...
- Unity引擎 UGUI
Unity UGUI讲解 1.导入UI图片资源 2.设置参数: TextureType(纹理类型) 精灵 2D and UI SpriteMode(精灵模式) Single(单) multiple( ...
- pycuda installation error: command 'gcc' failed with exit status 1
原文:python采坑之路 Setup script exited with error: command 'gcc' failed with exit status 1 伴随出现"cuda ...
- Centos7 Openstack - (第二节)添加认证服务(Keystone)
Centos7 install Openstack - (第二节)添加认证服务(Keystone) 我的blog地址:http://www.cnblogs.com/caoguo 根据openstack ...
- 如何创建一个项目,让gitlab自动触发jenkins进行构建
前进是:你已经配置好jenkins+gitlab自动化布置了,这里只是常规构建新的项目时,需要做的配置,记录下来,以免忘了又着急 参考这篇博客: https://www.jianshu.com/p/e ...
- CodeCombat代码全记录(Python学习利器)--Kithgard地牢代码1
Kithgard地牢注意:在调用函数时,要在函数的后面加上括号内容,否则在python中,将不会认为你在调用这个函数内容,而你的英雄将像木头一样站在原地不会执行上左下右的移动!!! hero.move ...
- 在Unity中对注册表的信息进行操作
问题1 在对注册表进行操作时无法生成注册表相关的类 解决办法: 增加头文件using Microsft.Win32; 问题2 在运行程序时报错同时注 ...