WA 0pts 求调
查看原帖
WA 0pts 求调
757139
zsh_haha楼主2024/8/26 16:02
#include<bits/stdc++.h>
using namespace std;
int n,m,tot;
long long a[1003];
long long f[11][102][1003];
int f1(int x){
	int ans=0;
	while(x){
		ans+=x%2;
		x/=2;
	}
	return ans;
}
bool check(int x,int y){
	return (y|(y<<1)|(y>>1))&x;
} 
int main(){
	cin>>n>>m;
	for(int i=0;i<(1<<n);i++){
		if((i&(i<<1))==0){
			a[++tot]=i;
		}
	}
//	f[0][0][0]=1;
	for(int i=1;i<=tot;i++){
		f[1][f1(i)][i]=1;
	}
	for(int i=2;i<=n;i++){
		for(int j=1;j<=tot;j++){
			int num=f1(a[j]);
			for(int k=1;k<=tot;k++){
				if(!check(a[j],a[k])){
					for(int q=num;q<=m;q++){
						f[i][q][j]+=f[i-1][q-num][k];
					}
				}	
			}
		}
	}
	long long ans=0;
	for(int i=1;i<=tot;i++){
		ans+=f[n][m][i];
	}
	cout<<ans; 
    return 0;
}
2024/8/26 16:02
加载中...