HDU 1992 Tiling A Grid with dominoes (pressure DP)

Source: Internet
Author: User

Problem descriptionwe wish to tiles a grid 4 units high and N units long with rectangles (dominoes) 2 units by one unit (in either orientation). For example, the figure shows the five different ways, a grid 4 units high and 2 units wide could be tiled.



Write a program this takes as input the width, W, the grid and outputs the number of different ways to tile a 4-by-w gr Id.

Inputthe first line of input contains a single integer N, (1≤n≤1000) which are the number of datasets that follow.
Each dataset is contains a single decimal integer, the width, W, and the grid for this problem instance.

Outputfor each problem instance, there are one line of output:the problem instance number as a decimal integer (Start Coun Ting at one), a single space and the number of tilings of a 4-by-w grid. The values of W would be chosen so the count would fit in a 32-bit integer.

Sample Input
3237

Sample Output
1 52 113 781

A location of 1 stands for a vertical downward brick.


#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <queue> #include <stack> #include <vector> #include <set> #include <map > #define L (x) (x<<1) #define R (x) (x<<1|1) #define MID (x, y) ((x+y) >>1) #define EPS 1e-8#define fre (i, A, b) for (i = A; I <b; i++) #define MEM (T, v) memset ((t), V, sizeof (t)) #define SF (n) scanf ("%d", &n) #defin          e SFF (A, b) scanf ("%d%d", &a, &b) #define SFFF (a,b,c) scanf ("%d%d%d", &a, &b, &c) #define PF Printf#define Bug pf ("hi\n") using namespace std; #define INF 0x3f3f3f3f#define n 22int dp[n][16];void dfs (int de P,int up,int down,int POS)//DEP line status is up update the next row status is down {if (pos>3) {Dp[dep+1][down]+=dp[dep][up];return;}     if (up& (1<<pos))//The previous line fills the POS position of the next line {DFS (dep,up,down,pos+1);                                          return;} DFS (dep,up,down| (   1<<pos), pos+1);   Vertically placed in the POS position of the dep+1 layer a vertical brick if (pos<=2&&! ( up& (1<< (pos+1)))//A brick is placed horizontally, occupying two positions Dfs (dep,up,down,pos+2);} int main () {int i,j,t,ca=0;dp[0][0]=1;fre (i,0,n) fre (j,0,16) if (Dp[i][j]) DFS (i,j,0,0), SF (t), while (t--) {SF (i);p f ("%d %d\n ", ++ca,dp[i][0]);} return 0;}








HDU 1992 Tiling A Grid with dominoes (pressure DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.