hdu 1143 递归

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

题意:求用2*1的矩阵充满3*n的方格有多少种不同的排列方案。

分析:看了网上的解析。其实递归就是找规律,测试数据如果多给几个谁都能a。刚开始的时候想画个3*3发现是x是奇数的话肯定不行,然后画3*4嗨,没画出来,脑子不够用。这就是数学不好的结果。http://blog.csdn.net/ma_nong/article/details/7339411   http://ningbohezhijun.blog.163.com/blog/static/587777622009962417638/

这两种解法是一样的,也比较符合我的逻辑就抄袭了。败笔。

View Code
// I'm lanjiangzhou
//C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
//C++
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cctype>
#include <stack>
#include <string>
#include <list>
#include <queue>
#include <map>
#include <vector>
#include <deque>
#include <set>
using namespace std;

//*************************OUTPUT*************************
#ifdef WIN32
#define INT64 "%I64d"
#define UINT64 "%I64u"
#else
#define INT64 "%lld"
#define UINT64 "%llu"
#endif

//**************************CONSTANT***********************
#define INF 0x3f3f3f3f

// aply for the memory of the stack
//#pragma comment (linker, "/STACK:1024000000,1024000000")
//end

const int maxn =35;
int n;
int f[maxn];

void init(){
    for(int i=4;i<=30;i++){
        if(i%2==1)  f[i]=0;
        else f[i]=f[i-2]*f[2];
        int j=i-4;
        while(j>=0){
            f[i]+=2*f[j];
            j-=2;
        }
    }
    //int sum=0;
    //for(int i=4;i<)
}
int main(){
    f[0]=1;  f[2]=3;
    init();
    while(scanf("%d",&n)!=EOF){
        if(n==-1) break;
        if(n%2==1){
            printf("0\n");
        }
        else printf("%d\n",f[n]);
    }
    return 0;
}

 

posted @ 2013-04-06 15:45  南下的小程序员  阅读(161)  评论(0编辑  收藏  举报