HDOJ_ACM_统计问题

 

Problem Description
在一无限大的二维平面中,我们做如下假设:
1、  每次只能移动一格;
2、  不能向后走(假设你的目的地是“向上”,那么你可以向左走,可以向右走,也可以向上走,但是不可以向下走);
3、  走过的格子立即塌陷无法再走第二次;

求走n步不同的方案数(2种走法只要有一步不一样,即被认为是不同的方案)。
 
Input
首先给出一个正整数C,表示有C组测试数据
接下来的C行,每行包含一个整数n (n<=20),表示要走n步。
 
Output
请编程输出走n步的不同方案总数;
每组的输出占一行。
 
Sample Input
2
1
2
 
Sample Output
3
7
 
Code
View Code
Key points
for this question, print out the picture step by step, you will find the regular.
for f(1), you have zero point that you can go two roads, and  have one point that you can go three roads.
for f(2), you have two points that you can go two roads,  and  have one point that you can go three roads.
.....
f(n)=a*2+b*3
a=a+2*b
b=a+b
and firstly a=0, b=1
 
Also, you can use other formula:  f[i]=2*f[i-1]+f[i-2].
 

 

转载于:https://www.cnblogs.com/chuanlong/archive/2012/11/09/2763354.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值