• HDU 5673 Robot 数学


    Robot

    题目连接:

    http://acm.hdu.edu.cn/showproblem.php?pid=5673

    Description

    There is a robot on the origin point of an axis.Every second, the robot can move right one unit length or do nothing.If the robot is
    on the right of origin point,it can also move left one unit length.A route is a series of movement. How many different routes there are
    that after n seconds the robot is still located on the origin point?
    The answer may be large. Please output the answer modulo 1,000,000,007

    Input

    There are multiple test cases. The first line of input contains an integer T(1≤T≤100) indicating the number of test cases. For each test case:

    The only line contains one integer n(1≤n≤1,000,000).

    Output

    For each test case, output one integer.

    Sample Input

    3
    1
    2
    4

    Sample Output

    1
    2
    9

    Hint

    题意

    有一个机器人位于坐标原点上。每秒钟机器人都可以向右移到一个单位距离,或者在原地不动。如果机器人的当前位置在原点右侧,它同样可以
    向左移动单位距离。一系列的移动(左移,右移,原地不动)定义为一个路径。问有多少种不同的路径,使得(n)秒后机器人仍然位于坐标原点?
    答案可能很大,只需输出答案对(1,000,000,007)的模。

    题解:

    作为数学智障……

    象征性的oeis了一波,然后第一个就是……

    http://oeis.org/A001006

    公式抄过来就AC了……

    代码

    //(n+2)a(n) = (2n+1)a(n-1)+(3n-3)a(n-2)
    
    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1e6+7;
    const int mod = 1e9+7;
    long long dp[maxn];
    long long quickpow(long long  m,long long n,long long k)//返回m^n%k
    {
        long long b = 1;
        while (n > 0)
        {
              if (n & 1)
                 b = (b*m)%k;
              n = n >> 1 ;
              m = (m*m)%k;
        }
        return b;
    }
    void pre()
    {
        dp[1]=1;
        dp[2]=2;
        for(int i=3;i<maxn;i++)
            dp[i]=(1ll*(2*i+1)*dp[i-1]+1ll*(3*i-3)*dp[i-2])%mod*quickpow(i+2,mod-2,mod)%mod;
    }
    void solve()
    {
        int x;
        scanf("%d",&x);
        printf("%lld
    ",dp[x]);
    }
    int main()
    {
        pre();
        int t;scanf("%d",&t);
        while(t--)solve();
        return 0;
    }
  • 相关阅读:
    sitemap.xml生成方法(asp和php)(转)
    浏览器缓存机制(转)
    JavaScript在IE浏览器和Firefox浏览器中的差异总结(转)
    JavaScript的数组及其操作
    Google Maps和GIS开发资源收集
    js 字符串转换成数字(转)
    关于构造函数
    C#类型转化
    .net framework
    C#变量
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5427249.html
Copyright © 2020-2023  润新知