哈喽
2024-10-14 20:05:47
发布于:广东
17阅读
0回复
0点赞
直接上代码:
#include <bits/stdc++.h>
#define ll long long
#define DEBUG true
constexpr int MAXN = 505;
using namespace std;
string mp[MAXN];
int dp[MAXN][1024];
int dz[MAXN];
int kkb[MAXN][1024];
ll ans;
int n,m,zz;
int bz;
int toint(string s){
int sum = 0;
int cnt = 1;
for(int i = s.size() - 1;i >= 0;i --){
sum += (s[i] - '0') * cnt;
cnt *= 2;
}
return sum;
}
string decode(int s){
string sum = "";
while(s){
sum += (s % 2) + '0';
s /= 2;
}
int tmp = m - sum.size();
for(int i = 0;i < tmp;i ++){
sum += "0";
}
reverse(sum.begin(),sum.end());
return sum;
}
bool check(string z,string s,int k){
for(int i = 0;i < s.size();i ++){
if(s[i] == '0' and z[i] == '1'){
return 0;
}
}
for(int i = 0;i < z.size();i ++){
if(i < z.size() - 1 and z[i] == '1' and z[i + 1] == '1'){
return 0;
}
}
if(k > 0){
for(int i = 0;i < dz[k - 1];i ++){
string f = decode(dp[k - 1][i]);
bool flag = 1;
for(int j = 0;j < f.size();j ++){
if(z[j] == '1' and f[j] == '1'){
flag = 0;
}
}
if(flag == 1){
kkb[k][bz] = (kkb[k][bz] + kkb[k - 1][i]) % 1000000007;
}
}
} else {
kkb[k][bz] = 1;
}
return 1;
}
void DFS(string s,int b,string z,int k){
if(b == s.size()){
if(check(z,s,k) == 1){
dp[k][bz ++] = toint(z);
}
return;
}
string tmp = z;
tmp += '1';
DFS(s,b + 1,tmp,k);
tmp = z;
tmp += '0';
DFS(s,b + 1,tmp,k);
}
int main(){
cin >> n >> m;
zz = pow(2,m);
for(int i = 0;i < n;i ++){
for(int j = 0;j < m;j ++){
int x;
cin >> x;
mp[i] += x + '0';
}
bz = 0;
DFS(mp[i],0,{},i);
dz[i] = bz;
}
for(int i = 0;i < bz;i ++){
ans += kkb[n - 1][i];
ans %= 1000000007;
}
cout << ans - 1;
return 0;
}
这里空空如也
有帮助,赞一个