poj 3254

状态压缩DP基础题

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 const int maxn=15;
 6 const int mod=100000000;
 7 int num[maxn],s[200];
 8 int f[maxn][200],amoun[1<<13];
 9 int main()
10 {
11     //freopen("1.txt","r",stdin);
12     int m,n;
13     cin>>m>>n;
14     int i,j,tem;
15     amoun[0]=0;
16     for(i=1;i<(1<<n);i++) amoun[i]=amoun[i>>1]+(i&1?1:0);
17     for(i=0;i<m;i++)
18     {
19         for(j=0;j<n;j++)
20         {
21             scanf("%d",&tem);
22             if(!tem) num[i+1]|=(1<<j);
23         }
24     }
25     int tot=0;
26     for(i=0;i<(1<<n);i++)
27         if(!(i&(i<<1))) s[tot++]=i;//很妙啊
28     int w;
29     int ans=0,k;
30     f[0][0]=1;
31     for(i=1;i<=m;i++)
32     {
33         for(j=0;j<tot;j++)
34         {
35             if(!(num[i]&s[j]))
36             {
37                 for(w=0;w<tot;w++)
38                 {
39                     if(!(s[j]&s[w])&&!(s[w]&num[i-1]))
40                         f[i][j]=(f[i][j]+f[i-1][w])%mod;
41                 }
42             }
43         }
44     }
45     for(j=0;j<tot;j++)
46         if(!(num[m]&s[j]))
47             if(f[m][j]) ans=(ans+f[m][j])%mod;
48     cout<<ans<<endl;
49     return 0;
50 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值