Floor Tile | Pressure DP Exercises

Source: Internet
Author: User

There is a n*m (n<=5,m<=1000) of the chessboard, now there are 1*2 and 2*1 of small pieces of wood, to cover the entire board, how many ways? The answer only needs mod1,000,000,007.

I don't know the source of the problem, Qaq.

The range of N and M should be the same, but the value of n given by the topic is very small, which gives us the idea of using the pressure DP.

Assuming that the first column is already full, the second column is only related to the first column's effect on it, and similarly, the third column is only related to the second column's effect on it, and we can use the binary to represent the condition of a given column, which represents the state of a column, such as State=4, which has a column status of 00100. Use dp[i][state] to denote column I, the effect of column i-1 on it is the number of scenarios for state, and the number of scenarios per column can be achieved by searching, Dp[i][state]=sigma (Dp[i-1][la]) La can be filled into state.

Code:

1 //Paving Board2 //2015/10/223#include <cstdio>4#include <iostream>5#include <cstdlib>6#include <cmath>7#include <vector>8#include <cstring>9#include <algorithm>Ten #defineMAXN 100000000+50 One #defineINF 0x7fffffff A #defineXiao 1e-9 - #defineMoD 1000000007 - using namespacestd; the intdp[1005][ +],n,m; - voidDfsintIintJintStateintnext) - { -     if(j==N) +     { -dp[i+1][next]+=Dp[i][state]; +dp[i+1][next]%=MoD; A         return; at}//If the last row is enumerated, then the next column status is next, plus the number of scenarios for which the column status is State -     if(((1&LT;&LT;J) &state) >0) DFS (i,j+1, State,next);//if the line J position is already occupied, skip directly, search j+1 line -     if(((1&LT;&LT;J) &state) = =0) DFS (i,j+1, state,next| (1&LT;&LT;J));//if not occupied, try to fill in a 1*2 -     if(j+1<n&& (1&LT;&LT;J) &state) = =0&& (1<< (j+1) &state) = =0)) DFS (i,j+2, State,next);//If this location and the next position are not occupied, try putting a 2*1 -     return; - } in intMain () - { toCin>>n>>m; +Memset (DP,0,sizeof(DP)); -dp[1][0]=1; the      for(intI=1; i<=m;++i) *        for(intj=0;j< (1<<n); + +j) $         {Panax Notoginseng             if(Dp[i][j]) DFS (i,0J0); -                     } thecout<<dp[m+1][0]<<Endl; +     return 0; A}

Floor Tile | Pressure DP Exercises

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.