标签:== 组成 using data- key plm family width print
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 29357 | Accepted: 11373 |
Description
Input
Output
Sample Input
5 4 PHPP PPHH PPPP PHPP PHHP
Sample Output
6
Source
1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <cstring> 5 #include <iostream> 6 #include <algorithm> 7 using namespace std; 8 typedef long long LL; 9 const int MAX=101; 10 int n,m,num; 11 int f[MAX][(1<<10)][(1<<10)]; 12 int s[1030],c[1030]; 13 int allow[1030]; 14 bool ok(int x){ if ((x&(x<<1)) || (x&(x<<2))) return false; return true;} 15 int getnum(int x){ int an=0; while (x){ an+=x%2;x/=2;} return an;} 16 bool fit(int x,int y){return ((allow[x]&y)?false:true);} 17 void init(){ 18 int i,j; 19 char cc; 20 scanf("%d%d\n",&n,&m); 21 memset(allow,0,sizeof(allow)); 22 for (i=1;i<=n;i++){ 23 for (j=1;j<=m;j++){ 24 cc=getchar(); 25 if (cc==‘H‘){ 26 allow[i]+=(1<<(m-j)); 27 } 28 } 29 getchar(); 30 } 31 for (i=0;i<(1<<m);i++){ 32 if (ok(i)){ 33 s[++num]=i; 34 c[num]=getnum(i); 35 } 36 } 37 memset(f,0,sizeof(f)); 38 for (i=1;i<=num;i++){ 39 if (fit(1,s[i])){ 40 f[1][s[i]][0]=c[i]; 41 } 42 } 43 } 44 int main(){ 45 freopen ("cannon.in","r",stdin); 46 freopen ("cannon.out","w",stdout); 47 int i,j,k,l,ans=0; 48 init(); 49 for (i=2;i<=n;i++){ 50 for (j=1;j<=num;j++){ 51 if (fit(i,s[j])){ 52 for (k=1;k<=num;k++){ 53 if (fit(i-1,s[k]) && !(s[j]&s[k])){ 54 for (l=1;l<=num;l++){ 55 if (fit(i-2,s[l]) && !(s[l]&s[j]) && !(s[l]&s[k])){ 56 f[i][s[j]][s[k]]=max(f[i][s[j]][s[k]],f[i-1][s[k]][s[l]]+c[j]); 57 } 58 } 59 } 60 } 61 } 62 } 63 } 64 for (i=1;i<=num;i++){ 65 for (j=1;j<=num;j++){ 66 ans=max(ans,f[n][s[i]][s[j]]); 67 } 68 } 69 printf("%d",ans); 70 return 0; 71 }
标签:== 组成 using data- key plm family width print
原文地址:http://www.cnblogs.com/keximeiruguo/p/7611189.html