zoukankan      html  css  js  c++  java
  • poj 3254

    状压DP。位运算真是弱项

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<iostream>
     5 #include<queue>
     6 #define inc(i,l,r) for(int i=l;i<=r;i++)
     7 #define dec(i,l,r) for(int i=l;i>=r;i--)
     8 #define link(x) for(edge *j=h[x];j;j=j->next)
     9 #define mem(a) memset(a,0,sizeof(a))
    10 #define inf 1e9
    11 #define ll long long
    12 #define succ(x) (1<<x)
    13 #define NM 13
    14 using namespace std;
    15 int read(){
    16     int x=0,f=1;char ch=getchar();
    17     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    18     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    19     return x*f;
    20 }
    21 int a[NM],b[succ(NM)],d[NM][succ(NM)],n,m,ans,s;
    22 int main(){
    23     n=read();m=read();
    24     inc(i,1,n)
    25     inc(j,1,m)
    26     if(!read())a[i]+=succ(j-1);
    27     inc(t,0,succ(m)-1)
    28     if((t&(t<<1))==0){
    29     b[++s]=t;
    30     if(!(t&a[1]))
    31     d[1][t]=1;
    32     }
    33     inc(i,2,n){
    34     inc(t,1,s){
    35         if(b[t]&a[i])continue;
    36         inc(v,1,s)
    37         if(!(b[v]&b[t]))
    38         d[i][b[t]]+=d[i-1][b[v]];
    39 //        printf("%d %d
    ",b[t],d[i][b[t]]);
    40     }
    41     }
    42     inc(t,0,succ(m)-1)(ans+=d[n][t])%=100000000;
    43     printf("%d
    ",ans);
    44     return 0;
    45 }
    View Code
  • 相关阅读:
    字符串的长度 -- js
    导入drupal中文语言包
    ubuntu修改iP地址
    人生需要苦难和敌人
    Drupal.theme未解之谜
    如何定义带下标的js数组
    smtp admin email 似乎可以考虑在
    js中的apply 和 call
    js 点号 中括号
    代码调试
  • 原文地址:https://www.cnblogs.com/onlyRP/p/5055440.html
Copyright © 2011-2022 走看看