zoukankan      html  css  js  c++  java
  • poj 2411

    #include<iostream>
    #include<stdio.h>
    #include<cstring>
    #include<algorithm>
    #define max( a,b ) ( (a)>(b)?(a):(b) )
    using namespace std;
    
    long long N,M,dp[12][4097];
    void DFS( int sta, int c,long long stu,long long ans )
    {
        if( sta >= M )return;
        DFS( sta+1,c,stu,ans );
        if( !(stu&(1<<sta)) && !(stu&(1<<(sta-1))) )
        {
            long long t = stu|(1<<sta)|(1<<(sta-1));
            if( dp[c][t] == -1 )dp[c][t]  = ans;
            else                dp[c][t] += ans;
            DFS( sta+1,c,t,ans);
        }
    }
    int main( )
    {
        while( scanf("%I64d%I64d",&N,&M) && N + M )
        {
            memset( dp,-1,sizeof(dp) );
            dp[0][(1<<M)-1] = 1;
            for( int i = 1; i <= N; i++ )
            for( int j = 0; j < (1<<M); j++ )
             if( dp[i-1][j] != -1 )
             {
                dp[i][(~j)&((1<<M)-1)] =  dp[i-1][j];
                DFS( 1,i,(~j)&((1<<M)-1), dp[i-1][j] );
             }
            long long res = max(0,dp[N][(1<<M)-1]);
            printf("%I64d\n",res);
        }
        return 0;
    }
    

      

  • 相关阅读:
    字符串匹配的KMP算法(转)
    二分查找谜题
    快排的优化--说说尾递归
    ZR提高失恋测4
    CF1209
    ZR普转提2
    ZR提高失恋测3
    ZR提高失恋测2(9.7)
    ZR9.8普转提
    CF1214
  • 原文地址:https://www.cnblogs.com/wulangzhou/p/3075617.html
Copyright © 2011-2022 走看看