zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    轻量级锁和偏向锁等
    桥接模式
    适配器模式
    建造者模式
    2-工厂模式
    Swift
    给视图添加点击波纹效果swift5
    Xcode 支持真机版本路径
    22个常用开源库(most swift)
    Github上关于iOS的各种开源项目集合
  • 原文地址:https://www.cnblogs.com/lj030/p/3128788.html
Copyright © 2011-2022 走看看