Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

实在找不到哪里错了,discuss能找到的数据都过了,附代码

Posted by ssq515 at 2016-07-14 20:50:10 on Problem 1185
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int m,n;
char s[15];
int mp[100];
int valid[1000];
int cnt;
int dp[105][70][70];//二维此行,三维前一行 
bool judge(int x){
	if(x&(x<<1)) return false;
	if(x&(x<<2)) return false;
	return true;
}
void get_valid(){
	cnt=0;
	for(int i=0;i< 1<<m;i++){
		if(judge(i)) valid[cnt++]=i;
	}
}
bool can(int x,int y){
	if(x&y) return false;
	return true;
}
int count1(int x)
{
	int num=0;
	while(n){
		num++;
		n&=(n-1);
	}
	return num;
}
int main()
{
	while(~scanf("%d%d",&n,&m)){
		memset(dp,-1,sizeof(dp));
		for(int i=0;i<n;i++){
			mp[i]=0;
			scanf("%s",s);
			for(int j=0;j<m;j++){
				if(s[i]=='H') mp[i]|=(1<<j);
			}
		}
		get_valid();
		for(int i=0;i<cnt;i++)
			dp[0][i][0]=count1(valid[i]);
		for(int i=1;i<n;i++){
			for(int j=0;j<cnt;j++){
				if(can(mp[i],valid[j])){
					int num=count1(valid[j]);
					for(int k=0;k<cnt;k++){
							if(valid[k]&valid[j]) continue;
								for(int p=0;p<cnt;p++){
									if(dp[i-1][k][p]==-1) continue;
									if(valid[j]&valid[p]) continue;
									dp[i][j][k]=max(dp[i][j][k],dp[i-1][k][p]+num);
								}
					}
				}
			}
		}
		int ans=0;
		for(int k=0;k<n;k++)
			for(int i=0;i<cnt;i++)
				for(int j=0;j<cnt;j++)
					ans=max(ans,dp[k][i][j]);
		printf("%d\n",ans);
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator