状压求助
查看原帖
状压求助
538023
shenmingxuan楼主2023/2/11 10:40

RT

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_INT = 2147483647;
const int INF = 0x3f3f3f3f;
const int MAXN = 200010;
const int MOD = 100000000;
int in(){
	int x = 0,f = 1;
	char c = getchar();
	while (!isdigit(c)){
		if (c == '-'){
			f = -1;
		}
		c = getchar();
	}
	while(isdigit(c)){
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}
int st[2000+1];
int mp[13];
int f[13][2000+1];
bool w[2000+1][2000+1];
int n,m;
signed main(){
	//freopen("xxx.in","r",stdin);
	//freopen("xxx.out","w",stdout);
	for(int i = 0;i <= (1<<12)-1;i++){
		if((i & (i>>1)) == 0){
			st[0]++;
			st[st[0]] = i;
		}
	}
	for(int i = 1;i <= st[0];i++){
		for(int j = i;j <= st[0];j++){
			if((st[i]&st[j]) == 0){
				w[i][j] = true;
				w[j][i] = true;
			}
		}
	}
	cin >> m >> n;
	for(int i = 1;i <= m;i++){
		int v = 0;
		for(int j = 1;j <= n;j++){
			int x;
			cin >> x;
			v = v*2+x;
		}
		mp[i] = v;
	}
	f[0][1] = 1;
	for(int i = 1;i <= m;i++){
		for(int j = 1;j <= st[0];j++){
			if((st[j]|mp[i]) == mp[i]){
				for(int k = 1;k <= st[0];k++){
					if(f[i-1][k] != -1 && w[j][k]){
						f[i][j] = (f[i][j]+f[i-1][k])%MOD;
					}
				}
			}
			else{
				f[i][j] = -1;
			}
		}
	}
	int ans = 0;
	for(int i = 1;i <= st[0];i++){
		if(f[m][i] != -1){
			ans = (ans + f[m][i])%MOD;
		}
	}
	cout << ans << endl;
	return 0;
}
2023/2/11 10:40
加载中...