纪念自己第一次理解状压dp写出来的
Corn Fields G
详解在注释中
//#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << "*" << x << endl;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define lowbit(x) x &(-x);
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef unsigned int ui; /// 0~(2^32)-1
typedef unsigned long long ull; ///0~(2^64)-1
const int inf = 0x3f3f3f3f;
const double eps = 1e-9;
const int P = 131; ///或者P=13331
const int N = 1e5 + 100;
const int M = 2e6 + 7;
const int mod = 100000000;
// #define int ll ///define后面不需要“;”
int n, m, res;
int dp[20][1 << 20], mp[1 << 20];
void AC()
{
cin >> m >> n;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
{
int x;
cin >> x;
mp[i] |= (x << (n - j));///看成正的二进制数
// mp[i] |= (x << (j - 1));///看成反的二进制数
}
for (int i = 0; i < (1 << n); i++)
{
if ((i & (i << 1)) || (i & (i >> 1)))
continue;
if ((mp[1] | i) != mp[1]) ///
continue;
dp[1][i] = 1;
}
for (int i = 2; i <= m; i++) ///
{
for (int j = 0; j < (1 << n); j++) ///
{
if ((j & (j << 1)) || (j & (j >> 1)))
continue;
if ((mp[i] | j) != mp[i])
continue;
for (int k = 0; k < (1 << n); k++)
{
if ((k & (k << 1)) || (k & (k >> 1)))
continue;
if ((mp[i - 1] | k) != mp[i - 1])
continue;
// if (j & k)
// continue;
// dp[i][j] += dp[i - 1][k];
// dp[i][j] %= mod;
if ((j & k) == 0) ///注意位运算的优先级焯
{
dp[i][j] += dp[i - 1][k];
dp[i][j] %= mod;
}
}
}
}
for (int i = 0; i < (1 << n); i++)
{
res += dp[m][i];
res %= mod;
}
cout << res << endl;
}
signed main() ///必须返回int类型
{
IOS;
// freopen("T:\\in.txt", "r", stdin);
// freopen("T:\\out.txt", "w", stdout);
int _ = 1;
while (_--)
AC();
fclose(stdin);
fclose(stdout);
return 0;
}
/// |\_/|
/// | @ @ Woof!
/// | <> _
/// | _/\------____ ((| |))
/// | `--' |
/// ____|_ ___| |___.'
/// /_/_____/____/_______|
/// I am here to guard this code, woof!