Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
头文件改成c++的就过了,g++就wa#include <cstdio> #include <cstring> int n,m; int sta[60],cou[100]; int dp[110][60][60]; int map[110]; char str[12]; int max(int a,int b) { if(a > b) return a; return b; } int main() { int i,j,k,p; int sp,tmp; while(~scanf("%d %d",&n,&m)) { memset(map,0,sizeof(map)); memset(dp,-1,sizeof(dp)); memset(cou,0,sizeof(cou)); for(i = 0; i < n; i++) { scanf("%s",str); for(j = 0; j < m; j++) { if(str[j] == 'H') map[i]+=(1<<j); } } sp = 0; tmp = (1<<m); for(i = 0; i < tmp; i++) { if(!(i&(i<<2)) && !(i&(i<<1))) { p = i; while(p) { cou[sp]++; p&=(p-1); } sta[sp++] = i; } } for(i = 0; i < sp; i++) { if(!(map[0]&sta[i])) { dp[0][i][0] = cou[i]; } } for(i = 1; i < n; i++) { for(j = 0; j < sp; j++) { if(!(map[i]&sta[j])) { for(k = 0; k < sp; k++) { if(!(map[i-1]&sta[k]) && !(sta[j]&sta[k])) { for(p = 0; p < sp; p++) { if(!(sta[p]&sta[j]) && !(sta[p]&sta[k]) && dp[i-1][k][p]!=-1) { dp[i][j][k] = max(dp[i][j][k],dp[i-1][k][p]+cou[j]); } } } } } } } tmp = 0; for(i = 0; i < n; i++) { for(j = 0; j < sp; j++) { for(k = 0; k < sp; k++) { tmp = max(tmp,dp[i][j][k]); } } } printf("%d\n",tmp); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator