写的对不对先不说,我只是想知道为什么加了一个模运算之后输出就变成负随机数了
输入样例是:
2 3
1 1 1
0 1 0
/*
Luogu P1879 Corn Fields G
https://www.luogu.com.cn/problem/P1879
*/
#include "iostream"
using namespace std;
const int mod=100000000;
int f[1][1<<12];
int m, n, temp;
bool field[13], valid[4100][4100], ans;
bool check(int x, int y){
for(int i=0;i<16;i++){
if((x>>i)%2==(y>>i)%2) return false;
}
return true;
}
bool soil(int state, int ground){
if((ground|state)>ground) return false;
return true;
}
int main(){
cin >> m >> n;
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin >> temp;
field[i]=field[i]*2+temp;
}
}
for(int i=0;i<4096;i++){
for(int j=i+1;j<4096;j++){
valid[i][j]=valid[j][i]=check(i, j);
}
}
f[0][field[0]]=1;
int pre=1, now=0;
for(int i=1;i<m;i++){ // row
swap(pre, now);
for(int i=0;i<4096;i++){ // prevous state
if(!f[pre][i]) continue;
for(int j=0;j<4096;j++){ // ground now
if(valid[i][j] && (j|field[i-1])<=field[i-1]) f[now][j]=(f[now][j]+f[pre][i])%mod;
}
}
}
int ans=0;
for(int i=0;i<4096;i++){
ans=(ans+f[now][i])%mod;
}
cout << ans;
}