hdu 4363 Draw and paint
来源:互联网 发布:与明星合照软件 编辑:程序博客网 时间:2024/04/19 18:05
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4363
题目大意:求对一个矩形在奇数步横切,偶数步纵切,且每进行一步将其中一部分染色,颜色同4种,相邻颜色不同色。求种数。
题目思路:dp[i][n][m][u][d][l][r],i表示是奇数还是偶数步,后面表示高,宽,四个方向的颜色。
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<string>#include<queue>#include<algorithm>#include<vector>#include<stack>#include<list>#include<iostream>#include<map>using namespace std;#define inf 0x3f3f3f3f#define Max 110#define mod 1000000007int max(int a,int b){ return a>b?a:b;}int min(int a,int b){ return a<b?a:b;}int dp[2][41][41][5][5][5][5];int dfs(int i,int n,int m,int u,int d,int l,int r){ if(dp[i][n][m][u][d][l][r]!=-1) return dp[i][n][m][u][d][l][r]; int ans=0,tmp=0; int w,h,co,co2; for(co=1;co<=4;co++) if(co!=l&&co!=r&&co!=u&&co!=d) ans++; if(i==1) { for(co=1;co<=4;co++) { if(co==l||co==r||co==u) continue; for(co2=1;co2<=4;co2++) { if(co2==l||co2==r||co2==d||co==co2) continue; tmp++; } } tmp*=(n-1); for(h=1;h<n;h++) { for(co=1;co<=4;co++) { if(co==l||co==r||co==d) continue; ans=(ans+dfs(1-i,h,m,u,co,l,r))%mod; } for(co=1;co<=4;co++) { if(co==l||co==r||co==u) continue; ans=(ans+dfs(1-i,h,m,co,d,l,r))%mod; } } } else { for(co=1;co<=4;co++) { if(co==l||co==u||co==d) continue; for(co2=1;co2<=4;co2++) { if(co2==r||co2==u||co2==d||co==co2) continue; tmp++; } } tmp*=(m-1); for(w=1;w<m;w++) { for(co=1;co<=4;co++) { if(co==r||co==u||co==d) continue; ans=(ans+dfs(1-i,n,w,u,d,l,co))%mod; } for(co=1;co<=4;co++) { if(co==l||co==u||co==d) continue; ans=(ans+dfs(1-i,n,w,u,d,co,r))%mod; } } } return dp[i][n][m][u][d][l][r]=ans-tmp;}int main(){ int t,n,m; scanf("%d",&t); memset(dp,-1,sizeof(dp)); while(t--) { scanf("%d%d",&n,&m); printf("%d\n",dfs(1,n,m,0,0,0,0)); }}
- hdu 4363 Draw and paint
- hdu 4363 Draw and paint
- HDU 4363 Draw and paint (DP)
- HDU 4363 Draw and paint DP
- hdu4363 Draw and paint(hard DP )
- Canvas&Paint[]Canvas:draw
- MetaFile and Draw
- CG : Draw Line And Draw Circle
- hdu 4450 Draw Something
- hdu 4450 Draw Something
- Hdu 4450 - Draw Something
- hdu 4450 Draw Something
- hdu 4450 Draw Something
- HDU 4450 Draw Something
- HDU 4450 Draw Something
- HDU 4450 Draw Something
- Paint fence and house
- java中paint方法与draw方法有什么不同
- POJ 2186Popular Cows(Tarjan)
- 嵌入式笔试
- 实在是太水了
- Objective-C语法之KVO的使用
- RMAN 初学者指南
- hdu 4363 Draw and paint
- RTEMS 为什么必须使用GNU的工具链开发?
- java-复制文件
- 进程枚举
- C++ 中将构造函数,析构函数声明为private,protected
- delphi学习笔记_查询、插入、删除、修改
- memcached内存管理(1) ----------------slabs
- C#中HashTable的用法
- jquery DOM 事件冒泡 魔法图书馆