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 ...
随机推荐
- Vue解决移动端localhost无数据问题
正常web端调用后台接口时使用localhost或者ip都能访问后台数据,但是在移动端上使用localhost却无法访问后台数据 这时候需要把localhost改成ip就可以在移动端上访问后台数据了
- 蛤玮学计网 -- 简单的判断ip
心累 , 狗日的想了好多数据 , ......啥也不说了 我去哭一会 . #include<stdio.h> #include<string.h> #include<m ...
- 关于将电脑背景+chrome等网页改成护眼豆沙绿
常用电脑的人都知道,白色等其他对比度大的颜色对眼伤害大,所以需换成柔和的豆沙绿,可长时间保证眼睛的不疲劳 windows浏览器: >>>>在桌面点右键,依次选属性(proper ...
- Spring Cloud (12) 服务网关-基础
通过前几篇介绍,已经可以构建一个简单的微服务架构了,如下图: 通过eureka实现服务注册中心以及服务注册发现,通过ribbon或feign实现服务的消费以及负载均衡,通过spring cloud c ...
- SVN系列学习(四)-TortoiseSVN其他操作
1.新建分支 第一步:从SVN上CheckOut一份,要作为分支模板的文件 第二步:右击[TortoiseSVN]-选择[Branch/tag] 备注说明,[指明分支路径] 第三步:删除电脑上的ZJH ...
- reactnative(1) - RefreshControl 使用案例
'use strict'; import React, { Component } from 'react'; import { AppRegistry, ScrollView, StyleSheet ...
- [ Luogu Contest 10364 ] TG
\(\\\) \(\#A\) 小凯的数字 给出两个整数\(L,R\),从\(L\)到\(R\)按顺序写下来,求生成整数对\(9\)取模后的答案. 例如\(L=8,R=12\),生成的数字是\(8910 ...
- 将子节点的所有父节点ID合并成一个字符串,并更新表
begin for cur_dept in (select SLCATALOG_ID from T_GIS_SLCATALOG) loop UPDATE T_GIS_SLCATALOG SET PAT ...
- Android RecyclerView notifyDataSetChanged不起作用
一般listview设置完data后调用notifyDataSetChanged便可刷新布局界面,然而recycleview调用这个方法却没有任何反应.对于很多不熟悉recycleview的话很容易躺 ...
- 依存分析 Dependency Parsing
依存分析 Dependency Parsing 句子成分依存分析主要分为两种:句法级别的和语义级别的 依存句法分析 syntactic dependency parsing 语义依存分词 semant ...