状压板题样例不过WA+RE0pts求助
查看原帖
状压板题样例不过WA+RE0pts求助
670355
Nuclear_Fish_cyq楼主2023/5/12 19:17
#include <bits/stdc++.h>
using namespace std;
int n, m, cnt;
long long f[25][100][4005], a[4005], b[4005], ans;
bool fl[25][25];
void dfs(int l, int k, int c){
	if(c >= m){
		cnt++;
		a[cnt] = k;
		b[cnt] = l;
		return;
	}
	if(!fl[cnt + 1][c]){
		dfs(l, k, c + 1);
	}
	dfs(l, k, c + 1);
	dfs(l + (1 << c), k + 1, c + 2);
	return;
}
bool check(int p, int q){
	if(b[p] & b[q]){
		return false;
	}
	if((b[p] << 1) & b[q]){
		return false;
	}
	if(b[p] & (b[q] << 1)){
		return false;
	}
	return true;
}
int main(){
	std::ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			int t;
			cin >> t;
			fl[i][j] = (bool)t;
		}
	}
	dfs(0, 0, 0);
	for(int i = 1; i <= cnt; i++){
		f[1][i][a[i]] = 1;
	}
	for(int i = 2; i <= n; i++){
		for(int j = 1; j <= cnt; j++){
			for(int l = 1; l <= cnt; l++){
				if(check(j, l)){
					for(int q = a[j]; q <= cnt; q++){
						f[i][j][q] += f[i - 1][l][q - a[j]];
						f[i][j][q] %= 100000000;
					}
				}
			}
		}
	}
	for(int i = 1; i <= cnt; i++){
		for(int j = 0; j <= n * m; j++){
			ans += f[n][i][j];
			ans %= 100000000;
		} 
	}
	cout << ans << endl;
	return 0;
}
2023/5/12 19:17
加载中...