POJ 2506 Tiling Recursion

Source: Internet
Author: User

Topic Links:

http://poj.org/problem?id=2506

Title Description:

There are 2*1 and 2*2 two kinds of porcelain pieces, asked how many ways to pave the 2*n graphics?

Problem Solving Ideas:

Using the recursive idea, the 2*n can be transferred from the state of the n-1 and a piece of vertical 2*1 porcelain, or by the state of the (n-2) plus a piece of 2*2 porcelain or two pieces of 2*1 horizontally.

Recursive formula can be derived: dp[n] = dp[n-1] + dp[n-2]*2;

AC Tips:

(1): From the output sample can be seen to use a large number to represent, probably need about 90 bits.

(2): 2*0 not 0 ways? After countless times WA, proved to be one, unexpectedly is a!!!!!!! , but also drunk, hard to think for a long.

1#include <cstdio>2#include <cstring>3#include <cstdlib>4#include <iostream>5 using namespacestd;6 #defineMAXN 907 intdp[251][MAXN], A[MAXN];8 9 intMain ()Ten { One     intN, I, J; AMemset (DP,0,sizeof(DP)); -dp[0][0] =1; -dp[1][0] =1; thedp[2][0] =3; -      for(i=3; i<251; i++)//marking, storing all the results -     { -         intYu =0; +          for(j=0; j<maxn; J + +)//Large number operation -         { +             ints = dp[i-2][j]*2+ Yu + dp[i-1][j]; ADP[I][J] = s%Ten; atYu = S/Ten; -         } -     } -      while(SCANF ("%d", &n)! =EOF) -     { -i = MAXN-1; in          while(Dp[n][i] = =0)//remove leading 0 -i--; to          for(; I >=0; i--) +printf ("%d", Dp[n][i]); -printf ("\ n"); the     } *     return 0; $}

POJ 2506 Tiling Recursion

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.