ZOJ 2563 Long Dominoes (like pressure DP) explanations

The meaning of problems: n * m grid, rectangular 3 * 1 just fill it, a rectangle can not overlap, and asked to fill several methods

Ideas: poj2411 advanced version. We can know that when determining the two consecutive lines of pendulum method, then the next line is also OK. When the first row there are empty, then the third row must be used to fill a 1 * 3; and when the first row of the second line is not empty empty, must not fill the third row; when the first empty row the second line is not empty, this can not exist; the current two lines did not empty, I fill the box is up to 1 * 3.

Code:

#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 11 + 5;
const int M = maxn * 30;
constSEED = ULL 131 is ;
 const  int INF = 0x3f3f3f3f ;
 const  int the MOD = + 1E4 . 7 ; 
LL DP [ 31 is ] [ . 1 << MAXN];
 int FAC [MAXN];
 int VIS [MAXN];
 int n-, m;
 int Perst ;
 // 0: 1 are empty: 2 on a non-empty: all non-empty 
int getSt () {
     int RET = 0 ;
     for ( int I = m - 1 ; I> = 0 ; i-- ) 
        RET = ret *3 + vis[i];
    return ret;
}
void dfs(int i, int j){
    if(j >= m){
        int st = getSt();
        dp[i][st] += dp[i - 1][prest];
        return;
    }
    int p = prest / fac[j] % 3;
    if(p == 0){
        vis[j] = 2;
        dfs(i, j + 1);
    }
    else if(p == 1) { 
        Display [j] = 0 ; 
        DFS (i, j + 1 ); 
    } 
    Else {
         if (j> = 2 && view [j - 1 ] == 1 && view [J - 2 ] == 1 ) { 
            Display [j] = Display [j - 1 ] = degree [J - 2 ] = 2 ; 
            DFS (i, j + 1 ); 
            view [j] = Display [j - 1 ] = degree [J - 2 ] = 1 ; 
        }
        view [j] =1;
        dfs(i, j + 1);
    }
}
int main(){
    fac[0] = 1;
    for(int i = 1; i <= 10; i++) fac[i] = fac[i - 1] * 3;
    while(~scanf("%d%d", &m, &n) && n + m){
        memset(dp, 0, sizeof(dp));
        dp[0][fac[m] - 1] = 1;
        for(int i = 1; i <= n; i++){
            for(int j = 0; j < fac[m]; j++){
                if(dp[i - 1][j] == 0) continue;
                memset(vis, 0, sizeof(vis));
                prest = j;
                dfs(i, 0);
            }
        }
        printf("%lld\n", dp[n][fac[m] - 1]);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/KirinSB/p/10960808.html