Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 纪念第一题状压DP

Posted by OZY123 at 2016-10-26 13:42:17 on Problem 3254
```#include<cstdio>
#include<cstring>
const int N=15;
const int M=1<<N;
const int MOD=100000000;
int n,m;
int map[N];//第i行的状态
int f[N][M];//第i行的状态为j有多少种不同的情况
int s[N][N];
bool check1 (int x,int y)
{
if ((x&y)!=0) return false;
return true;
}
bool check (int x)
{
return (x&(x<<1));
}
int main()
{
scanf("%d%d",&n,&m);
for (int u=1;u<=n;u++)
for (int i=1;i<=m;i++)
{
int x;
scanf("%d",&x);
if (x==1)
map[u]+=(1<<(i-1));
}
memset(f,0,sizeof(f));
int ooo=1<<m;
for (int u=0;u<=ooo;u++)
{
if ((u|map[1])!=map[1]) continue;
if (!check(u))
f[1][u]=1;
}
for (int u=2;u<=n;u++)
{
for (int i=0;i<=ooo;i++)
{
if ((i|map[u])!=map[u]) continue;
if (check(i)) continue;

for (int j=0;j<=ooo;j++)
{
if (f[u-1][j]==0) continue;
if (check1(i,j)==false) continue;
f[u][i]+=f[u-1][j];
f[u][i]%=MOD;
}
}
}
int ans=0;
for (int u=0;u<=ooo;u++)
{
ans+=f[n][u];
ans%=MOD;
}
printf("%d\n",ans);
return 0;
}```

Followed by: