码迷,mamicode.com
首页 > 其他好文 > 详细

hdu5306The mook jong(简单递推)

时间:2015-08-10 17:57:45      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

BC #50#简单递推

看了很多讲解的递推没有很懂,还好zzuspy思路简单清晰:

f(n):要放n个木桩,先考虑最后一个板砖如果放的话,the last one的前两个并不能放木桩,所以前n-3个板砖如果放木桩的话有f(n-3)中方案,如果不放木桩的话,有一种方案;

            最后一个板砖如果不放的话,是f(n-1)中方案;

所以f(n)=f(n-1)+f(n-3)+1;

还有一个hack点是爆Int的问题,但是比赛时并没有找到可以hack的代码T-T

The mook jong

 
 Accepts: 506
 
 Submissions: 1281
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
问题描述
ZJiaQ为了强身健体,决定通过木人桩练习武术。ZJiaQ希望把木人桩摆在自家的那个由1*1的地砖铺成的1*n的院子里。由于ZJiaQ是个强迫症,所以他要把一个木人桩正好摆在一个地砖上,由于木人桩手比较长,所以两个木人桩之间地砖必须大于等于两个,现在ZJiaQ想知道在至少摆放一个木人桩的情况下,有多少种摆法。
输入描述
输入有多组数据,每组数据第一行为一个整数n(1 < = n < = 60)
输出描述
对于每组数据输出一行表示摆放方案数
输入样例
1	
2
3
4
5
6
输出样例
1
2
3
5
8
12
技术分享
 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<string.h>
 4 #include<stdlib.h>
 5 #include<ctype.h>
 6 #include <map>
 7 #include <set>
 8 #include <cmath>
 9 #include <deque>
10 #include <queue>
11 #include <stack>
12 #include <cstdio>
13 #include <cctype>
14 #include <string>
15 #include <vector>
16 #include <cstdlib>
17 #include <cstring>
18 #include <iostream>
19 #include <algorithm>
20 #define LL long long
21 #define INF 0x7fffffff
22 using namespace std;
23 
24  
25 int main()
26 {
27     int n;
28     //freopen("test.txt","r",stdin);
29     int res;
30     long long a[65]={0};
31     a[1]=1;
32     a[2]=2;
33     a[3]=3;
34     a[4]=5;
35     a[5]=8;
36     for(int i=6;i<=60;i++){
37         a[i]=a[i-1]+a[i-3]+1;
38     }
39     while(scanf("%d",&n)!=EOF)
40     {
41         printf("%I64d\n",a[n]);
42     }
43     return 0;
44 }
View Code

 

hdu5306The mook jong(简单递推)

标签:

原文地址:http://www.cnblogs.com/sunshiniing/p/4718426.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!