20pts求条
查看原帖
20pts求条
772875
RAY091016楼主2025/7/22 10:09

AC on #1,#2,#11,其余全 WA。

code:

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,f[1<<10][1<<10][2],x[110],sum[110],ans;
char ch;
int lowbit(int x){
	return x&-x;
}
int get(int x){
	int cnt=0;
	while(x){
		cnt++;
		x-=lowbit(x);
	}
	return cnt;
}
signed main(){
    cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>ch;
			x[i]<<=1;
			if(ch=='H'){
				x[i]++;
			}
		}
	}
	for(int s=0;s<(1<<m);s++){
		sum[s]=get(s);
	}
	for(int s=0;s<(1<<m);s++){
		if(!((s&x[1])||(s&(s<<1))||(s&(s<<2)))){
			f[0][s][1]=sum[s];
		}
	}
	for(int l=0;l<(1<<m);l++){
		for(int s=0;s<(1<<m);s++){
			if(!((l&s)||(l&x[1])||(s&x[2])||(l&(l<<1))||(l&(l<<2))||(s&(s<<1))||(s&(s<<2)))){
				f[l][s][0]=sum[l]+sum[s];
			}
		}
	}
	for(int i=3;i<=n;i++){
		for(int l=0;l<(1<<m);l++){
			if(!((l&x[i-1])||(l&(l<<1))||(l&(l<<2)))){
				for(int s=0;s<(1<<m);s++){
					if(!((s&x[i])||(l&s)||(s&(s<<1))||(s&(s<<2)))){
						for(int t=0;t<(1<<m);t++){
							if(!((t&x[i-2])||(t&l)||(t&s)||(t&(t<<1))||(t&(t<<2)))){
								f[l][s][i&1]=max(f[l][s][i&1],f[t][l][(i-1)&1]+sum[s]);
							}
						}
					}
				}
			}
		}
	}
	for(int l=0;l<(1<<m);l++){
		for(int s=0;s<(1<<m);s++){
			ans=max(ans,f[l][s][n&1]);
		}
	}
	cout<<ans;
    return 0;
}
2025/7/22 10:09
加载中...