zoukankan      html  css  js  c++  java
  • POJ 3254 状态压缩

    题目链接  http://poj.org/problem?id=3254

    开始改变 自己写状态压缩的方式了  以前的那种写法 完全自创,很复杂一样;换了大牛的思路,,,不用 DFS 了 

    #include<iostream>
    #include<stdio.h>
    #include<cstring>
    #include<algorithm>
    #define mod 100000000
    using namespace std;
    
    int N,M,ans,map[13],cnt[(1<<13)],dp[13][(1<<13)];
    void inint( )
    {
        ans = 0;
        for( int i = 0; i < (1<<M); i++ )
            if( !(i&(i<<1)) )cnt[ans++] = i;
    }
    int main( )
    {
        int i,j,k,val;
        while( scanf("%d%d",&N,&M) != EOF)
        {
            memset( map,0,sizeof(map) );
            memset( dp, 0,sizeof(dp)  );
            for( i = 1; i <= N; i++ )
            for( j = 1; j <= M; j++ )
            {
                scanf("%d",&val);
                if( !val )map[i] |= ( 1<<(j-1) );
            }
            inint( );
            for( i = 0; i < ans; i++ )
            if( !(map[1]&cnt[i]) )
                   dp[1][i] = 1;
            for( i = 2; i <= N; i++ )
            for( j = 0; j <ans; j++ )
            {
                if( map[i-1]&cnt[j] )continue;
                for( k = 0; k < ans; k++ )
                {
                    if( (cnt[k]&map[i]) || (cnt[k]&cnt[j]) )continue;
                    dp[i][k] = (dp[i][k]+dp[i-1][j])%mod;
                }
            }
            int res = 0;
            for( i = 0; i < ans; i++ )
            res = (res + dp[N][i])%mod;
            printf("%d\n",res);
        }
        return 0;
    }
    

      

  • 相关阅读:
    第03组 Alpha冲刺(3/6)
    第03组 Alpha冲刺(2/6)
    第03组 Alpha冲刺(1/6)
    团队项目-选题报告
    第3组 团队展示
    福大软工 · BETA 版冲刺前准备(团队)
    Alpha 事后诸葛亮
    Alpha冲刺
    Alpha冲刺-(9/10)
    Alpha冲刺
  • 原文地址:https://www.cnblogs.com/wulangzhou/p/3061404.html
Copyright © 2011-2022 走看看