递推问题 hdu 2046 与1143的比对

2046

在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.
例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图:
 
Input
输入数据由多行组成,每行包含一个整数n,表示该测试实例的长方形方格的规格是2×n (0<n<=50)。
 
Output
对于每个测试实例,请输出铺放方案的总数,每个实例的输出占一行。
 
Sample Input
1 3 2
 
Sample Output
1 3 2
  ~ 1143

Problem Description
In how many ways can you tile a 3xn rectangle with 2x1 dominoes? Here is a sample tiling of a 3x12 rectangle.

 

Input
Input consists of several test cases followed by a line containing -1. Each test case is a line containing an integer 0 ≤ n ≤ 30.
 

Output
For each test case, output one integer number giving the number of possible tilings.
 

Sample Input
2 8 12 -1
 

Sample Output
3 153 2131

首先 分清一个概念 子状态的划分问题每一个字问题必须是互补想干的 这样才能够保证求解的时候不出现重复

比如2046中 f(n-2)*1而不是*2

2046中的f(n)就可以分为f(n-1) f(n-2)两种情况 因为之后的情况就是这两种情况的组合

而1143不可以  因为只有的n-6 n-8......都有属于自己的特解 所以不能只用f(n-2) f(n-4)来作为一个子状态

原文地址:https://www.cnblogs.com/z1141000271/p/5311986.html