nuc2016第一次月赛A

本文探讨了郭杰女士从原点出发,在不重复经过已访问点的情况下,行走n步的不同路径数量计算方法。通过递推算法实现了路径计数,并采用模运算确保数值大小在限定范围内。
描述

The first lady of our lab is GuoJie, GuoJie likes walking very much.

Today GuoJie walks from the original point (0, 0), everytime he(may be she?) can go up or left or right a step.

But she can't go back the point where she have visited.

For example, if he goes up a step, she will be at (1, 0) and she never comes back the point.

Now, if she can walk n(n <= 100000) steps, can you find how many ways she can walk? the result mod 1e9 + 7.

输入
There will be T (T <= 100) cases, each case will input a n.
输出
For each group of input integers you should output how many ways GuoJie can walk in one line, and with one line of output for each line in input.
样例输入
1
2
样例输出
7
#include <iostream>
#include<stdio.h>
using namespace std;
long long num[1000006];
void gon()
{
    long long a=1;
    long long  b=0;
    num[0]=1;
    for(int i=1;i<1000000;i++)
    {
        a=a+b;
        b=num[i-1]-a;
        num[i]=3*a+2*b;
        while(num[i]>=1000000007)
            num[i]-=1000000007;
    }
    num[0]=0;
    return ;
}

int main()
{
    int t,n;
    gon();
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        printf("%d\n",num[n]);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值