poj 2411 (状态压缩)

来源:互联网 发布:复旦金融硕士 知乎 编辑:程序博客网 时间:2024/06/02 19:45

第一道状态压缩,撒花~~~

/* * ===================================================================================== * *       Filename:  a.cpp *        Version:  1.0 *        Created:  2013-08-27 23:01:05 *       Revision:  none *       Compiler:  GNU C++ * *      Just like you,wait you forever~~ * * ===================================================================================== */#include <set>#include <map>#include <list>#include <queue>#include <stack>#include <cmath>#include <string>#include <cstdio>#include <vector>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define PB             push_back#define SIZE(x)        (int)x.size()#define clr(x,y)       memset(x,y,sizeof(x))#define MP(x,y)     make_pair(x,y)#define reads(n)       scanf ("%s", n)#define ALL(t)         (t).begin(),(t).end()#define FOR(i,n,m)     for (int i = n; i <= m; i ++)#define ROF(i,n,m)     for (int i = n; i >= m; i --)#define IT             iterator#define FF      first#define SSsecondtypedef long long               ll;typedef unsigned int            uint;typedef unsigned long long      ull;typedef vector<int>             vint;typedef vector<string>          vstring;typedef pair<int, int> PII;void RI (int& x){        x = 0;        char c = getchar ();        while (c == ' '||c == '\n')c = getchar ();        bool flag = 1;        if (c == '-'){                flag = 0;                c = getchar ();        }        while (c >= '0' && c <= '9'){                x = x * 10 + c - '0';                c = getchar ();        }        if (!flag)x = -x;}void RII (int& x, int& y){RI (x), RI (y);}void RIII (int& x, int& y, int& z){RI (x), RI (y), RI (z);}/**************************************END define***************************************/const ll mod = 1e9+7;const ll LINF = 1e18;const int INF = 1e9;const double EPS = 1e-8;const int N = (1 << 11);int n, m;ll dp[13][N];vint g[N];void init (){        FOR (i, 0, N-1)         g[i].clear ();        clr (dp, 0);}void dfs (int col, int x, int y){        if (col > n){                g[x].PB (y);                return;        }        dfs (col+1, (x<<1)+1, y<<1);        dfs (col+1, x<<1, (y<<1)+1);        if (col + 1 <= n)       dfs (col+2, x<<2, y<<2);}int main (){        while (cin >> n >> m, n||m){                if (m < n)      swap (m, n);                init ();                dfs (1, 0, 0);                dp[1][0] = 1;                FOR (i, 1, m){                        FOR (j, 0, (1<<n)-1){                                FOR (h, 0, SIZE (g[j])-1){                                        int v = g[j][h];                               //         cout << j << " " << v << endl;                                        dp[i+1][v] += dp[i][j];                                }                        }                }                cout << dp[m+1][0] << endl;        }}