骨牌鋪方格
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 27253 Accepted Submission(s): 13181
例如n=3時,爲2× 3方格,骨牌的鋪放方案有三種,如下圖:
/***************************
*
* acm: hdu-2046
*
* title: 骨牌鋪方格
*
* time: 2014.5.18
*
***************************/
//考察遞推求解
//斐波那契數列
#include <stdio.h>
#include <stdlib.h>
#define ll __int64
int fun(int n)
{
ll res;
if (n == 1)
{
res = 1;
}
else if (n == 2)
{
res = 2;
}
else
{
res = fun(n - 1) + fun(n - 2);
}
return res;
}
int main()
{
int n;
while (~scanf("%d", &n))
{
printf("%I64d\n", fun(n));
}
return 0;
}
//將遞歸轉化爲循環,打表方法(優點只循環一遍)
/***************************
*
* acm: hdu-2046
*
* title: 骨牌鋪方格
*
* time: 2014.5.18
*
***************************/
//考察遞推求解
//斐波那契數列
#include <stdio.h>
#include <stdlib.h>
#define ll __int64
ll a[51];
void fun(int n)
{
int i;
a[0] = 1;
a[1] = 2;
for (i = 2; i < 51; i++)
{
a[i] = a[i-1] + a[i-2];
}
}
int main()
{
int n;
fun(51);
while (~scanf("%d", &n))
{
printf("%I64d\n", a[n-1]);
}
return 0;
}