您的位置:首页 > 其它

HDU 2501 Tiling_easy version

2014-11-09 14:02 260 查看

http://acm.hdu.edu.cn/showproblem.php?pid=2501

递推公式:f[i]=f[i-1]+f[i-2]*2

思路:

1、对于i-1个来说剩两个直接补一个2*1的即可,有f[i-1]种

2、对于i-2个来说,剩四个,有三种方法:a、一个2*2;

b、两个横着的1*2;

c、两个竖着的1*2;

显然c中跟第一种冲突,所以有2*f[i-2]种方法由此推导出递推公式。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>

const int N=35;

using namespace std;

int f
 = {0,1,3};
int main(){
//    freopen("in.txt", "r", stdin);
    for(int i=3; i<=30; i++)
        f[i] = f[i-1] + f[i-2]*2;
    int cas;
    scanf("%d",&cas);
    while(cas--){
        int k;
        scanf("%d",&k);
        printf("%d\n",f[k]);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: