hdu1992 (Recursive)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1992

Test instructions: How many ways to pave 4*w squares with small rectangles of 1*2 and 2*1.

Analysis: If the newly added 1 columns, this column is vertical, there must be a[i] species, if the last added block to cross the right side of the boundary, not across to the penultimate column, then there is 4*a[i-2]; When crossing the right two boundary, there is no crossing the third boundary, there are 2*a[i-3] species, When the last three lines across the same time, there is no cross-fourth boundary, the simulation found that there are 3*a[i-4] species, that is, when the same time across the odd T-bar boundary, there is 2*a[i-t];t is even when there is 3*a[i=t]; so found a[i]=a[i-1]+4*a[i-2]+2*a[i-3 ]+3*a[i-4]+......+a[i-i]*b (i is an odd b=2, even b=3).

#include <cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<queue>#include<cstdlib>#include<vector>#include<Set>#include<map>#defineLL Long Long#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineN 10010using namespacestd; LL a[1010];voidinit () {a[0]=1; a[1]=1; a[2]=5; a[3]= One;  for(intI=4; i<= -; i++) {LL sum=a[i-1]+4*a[i-2]; LL b=2;  for(intj=i-3; j>=0; j--) {sum+=a[j]*b; if(b==2) b++; Elseb--; } A[i]=sum; }}intMain () {intt,n,cas=1;    Init (); scanf ("%d",&t);  while(t--) {scanf ("%d",&N); printf ("%d%i64d\n", cas++, A[n]); }}
View Code

hdu1992 (Recursive)

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.