zoj 3466 The Hive II
2012-09-28 10:53
597 查看
小hh插头dp http://www.notonlysuccess.com/index.php/plug-dp-complete/ 的第二题。
这题比第一题难处理一点,但是方法是一样的,用轮廓线扫一遍就好了,每个可行格子有且仅有两个插头,要分奇偶格子处理
两条轮廓线就像这样,然后层层扫描即可
这题比第一题难处理一点,但是方法是一样的,用轮廓线扫一遍就好了,每个可行格子有且仅有两个插头,要分奇偶格子处理
两条轮廓线就像这样,然后层层扫描即可
Run ID | Submit Time | Judge Status | Problem ID | Language | Run Time(ms) | Run Memory(KB) | User Name |
3065240 | 2012-09-28 01:02:51 | Accepted | 3466 | C++ | 2470 | 2748 | xym |
#include<cstdio> #include<cmath> #include<iostream> #include<cstdlib> #include<cstring> #include<algorithm> #include<vector> #include<queue> #include<map> #include<set> #include<string> #include<iterator> #include<stack> #define LL long long using namespace std; int n,m; int mov[2][4]={1,5,9,13,0,4,8,12}; int num[8]={0,1,1,2,1,2,2,3}; bool gp[10][10]; LL dp[5][1<<16]; char s[10]; int main() { while(~scanf("%d%d",&n,&m)) { memset(gp,0,sizeof(gp)); for(int i=0;i<m;i++) { scanf("%s",s); gp[s[0]-'A'+1][s[1]-'A'+1]=1; } memset(dp,0,sizeof(dp)); dp[4][0]=1; int sum=1<<16; for(int i=1;i<=n;i++) { for(int j=0;j<sum;j++) { if(j<(1<<15)) dp[0][j]=dp[4][(j<<1)]; else dp[0][j]=0; } for(int j=1;j<=4;j++) for(int sta=0;sta<sum;sta++) dp[j][sta]=0; for(int j=1;j<=4;j++) { for(int sta=0;sta<sum;sta++) { int k=(sta>>mov[0][j-1])&7; int st1=sta^(k<<mov[0][j-1]); if(gp[i][j*2]) { if(k==0) dp[j][sta]=dp[j-1][sta]; continue; } else { for(int x=0;x<8;x++) { if(num[k]+num[x]==2) { dp[j][sta]+=dp[j-1][st1^(x<<mov[0][j-1])]; } } } } } for(int j=0;j<sum;j++) dp[0][j]=0; for(int j=0;j<sum;j++) { if(j<(1<<15)) dp[0][j<<1]=dp[4][j]; } for(int j=1;j<=4;j++) for(int sta=0;sta<sum;sta++) dp[j][sta]=0; for(int j=1;j<=4;j++) { for(int sta=0;sta<sum;sta++) { int k=(sta>>mov[1][j-1])&7; int st1=(sta^(k<<mov[1][j-1])); if(gp[i][j*2-1]) { if(k==0) dp[j][sta]=dp[j-1][sta]; continue; } else { for(int x=0;x<8;x++) { if(num[k]+num[x]==2) { dp[j][sta]+=dp[j-1][st1^(x<<mov[1][j-1])]; } } } } } } cout<<dp[4][0]<<endl; } return 0; }
相关文章推荐
- ZOJ 3466 The Hive II 解题报告(插头DP)
- ZOJ 3466 The Hive II(插头DP)
- ZOj 3466 The Hive II
- ZOJ 3466 The Hive II (插头DP,变形)
- ZOJ 3466 The Hive II 插头DP
- ZOJ 3466 The Hive II
- zoj 3466 The Hive II(插头dp)
- zoj 3535 Gao the String II (ac自动机+dp)
- ZOJ3466-The Hive II
- zoj 3688 The Review Plan II
- ZOJ 3648 Gao the Grid II
- 模拟·The Archaeologist's Trouble II ·ZOJ 2058
- ZOJ 2058 The Archaeologist's Trouble II
- ZOJ-#3465 The Hive(字符串模拟)
- zoj 3535 Gao the String II(AC自动机+DP)
- zoj 3535 Gao the String II(ac自动机+dp)
- Zoj 3535 Gao the String II (AC自动机+dp)
- zoj 3688 The Review Plan II(容斥原理+禁位排列+逆元)
- ZOJ 3465 The Hive 暴力模拟
- ZOJ 3688 C The Review Plan II