统计问题

来源:互联网 发布:淘宝牛仔裤女 编辑:程序博客网 时间:2024/06/10 09:53
统计问题
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit

Status
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


#include<cstdio>using namespace std;int main(){long long int arr[21];arr[1] = 3;arr[2] = 7;for (int i = 3; i <= 20; i++){arr[i] = 2 * arr[i - 1] + arr[i - 2];}int n;while (scanf("%d", &n) != EOF){for (int i = 0; i < n; i++){int temp;scanf("%d", &temp);printf("%d\n", arr[temp]);}}}


0 0