标签:php targe code lang time href log ini def
http://poj.org/problem?id=1185
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 29176 | Accepted: 11303 |
Description
Input
Output
Sample Input
5 4 PHPP PPHH PPPP PHPP PHHP
Sample Output
6
Source
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 using namespace std; 6 #define LL long long 7 int e[105][15]; 8 int f[105][105][105]; 9 int N,M,tot,all; 10 int a[1005],t[1005]; 11 int g[105][105]; 12 int _g[105][105]; 13 int sol(int x) 14 { 15 int r=0; 16 for(int j=0;j<M;++j) 17 { 18 if(x&(1<<j)) { 19 r++; 20 for(int i=-2;i<=2;++i) 21 { 22 if(i==0||j+i<0||j+i>=M) continue; 23 if(x&(1<<(j+i))) return -1; 24 } 25 } 26 } 27 return r; 28 } 29 void init() 30 { 31 for(int i=0;i<all;++i) 32 { 33 int x=sol(i); 34 if(x!=-1){ 35 a[tot]=i; 36 t[tot++]=x; 37 } 38 } 39 } 40 bool ok(int _a,int x) 41 { 42 int A=a[_a]; 43 for(int i=0;i<M;++i) 44 if((A&(1<<i))&&e[x][M-i]) return 0; 45 return 1; 46 } 47 bool match(int _a,int _b) 48 { 49 int A=a[_a],B=a[_b]; 50 for(int i=0;i<M;++i) 51 if((A&(1<<i))&&(B&(1<<i))) return 0; 52 return 1; 53 } 54 int main() 55 { 56 int i,j,k=0; 57 while(scanf("%d%d",&N,&M)==2){tot=0; 58 all=(1<<M);memset(e,0,sizeof(e)); 59 memset(f,0,sizeof(f)); 60 memset(g,-1,sizeof(g)); 61 memset(_g,-1,sizeof(_g)); 62 for(i=3;i<=N+2;++i) 63 for(j=1;j<=M;++j){ 64 char c; 65 scanf(" %c",&c); 66 e[i][j]=c==‘P‘?0:1; 67 } 68 init(); 69 for(i=0;i<tot;++i) 70 for(j=3;j<=N+2;++j) 71 _g[i][j]=ok(i,j); 72 for(i=0;i<tot;++i) 73 for(j=0;j<tot;j++) 74 g[i][j]=match(i,j); 75 for(i=3;i<=N+2;++i) 76 { 77 for(int t1=0;t1<tot;++t1) 78 { 79 if(!_g[t1][i-2]) continue; 80 for(int t2=0;t2<tot;++t2) 81 { 82 if(!_g[t2][i-1]||!g[t1][t2]) continue; 83 for(int t3=0;t3<tot;++t3) 84 { 85 if(!_g[t3][i]||!g[t2][t3]||!g[t1][t3]) continue; 86 if(f[i][t2][t3]<f[i-1][t1][t2]+t[t3])f[i][t2][t3]=f[i-1][t1][t2]+t[t3]; 87 } 88 } 89 } 90 } 91 int ans=0; 92 for(int t1=0;t1<tot;++t1) 93 for(int t2=0;t2<tot;++t2) 94 if(ans<f[N+2][t1][t2])ans=f[N+2][t1][t2]; 95 printf("%d\n",ans); 96 } 97 return 0; 98 }
标签:php targe code lang time href log ini def
原文地址:http://www.cnblogs.com/zzqc/p/7481937.html