【DP】HDU 1143 Tri Tiling

来源:互联网 发布:ipad1 5.11软件下载 编辑:程序博客网 时间:2024/04/30 13:02

需要放满格子,所以N为奇数时ans应该为0;

当前格子放的状态用表示0-7的二进制来表示

初始化第一列时先令036为1

第i列可有前一列的状态转化而来

i-1列 当前第i列

  7->0

       6-> 1

       5-> 2

       4,7 ->  3 

         3 ->  4

         2 ->  5 

      1,7 ->  6

  3,6,0 ->  7  

#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#include <string>#include <iostream>#include <algorithm>using namespace std;#include <queue>#include <stack>#include <vector>#include <deque>#include <set>#include <map>#define IN     freopen ("in.txt" , "r" , stdin);#define OUT  freopen ("out.txt" , "w" , stdout);typedef long long  LL;const int MAXN = 1111111;//点数的最大值const int MAXM = 20006;//边数的最大值const int INF = 11521204;const int mod=1000000007;int dp[1111][9];int main(){    int n,m,q;    while(scanf("%d",&n),n!=-1)    {        memset(dp,0,sizeof(dp));        dp[0][7]=dp[1][0]=dp[1][3]=dp[1][6]=1;        for(int i=2;i<=n;i++)        {            dp[i][0]=dp[i-1][7];            dp[i][1]=dp[i-1][6];            dp[i][2]=dp[i-1][5];            dp[i][3]=dp[i-1][7]+dp[i-1][4];            dp[i][4]=dp[i-1][3];            dp[i][5]=dp[i-1][2];            dp[i][6]=dp[i-1][7]+dp[i-1][1];            dp[i][7]=dp[i][1]+dp[i][4]+dp[i-1][0];        }        printf("%d\n",dp[n][7]);    }    return 0;}

0 0