zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    CSS 背景
    CSS padding 属性
    CSS border 属性和 border-collapse 属性
    CSS margin 属性
    IEnumerable<T> 接口和GetEnumerator 详解
    discuz! X3.4特殊字符乱码解决方案
    Discuz通过修改文章标题更好的实现SEO的方法
    关于Discuz x3.3页面空白解决方法
    discuz x3.3标题的最少字数限制设置方法
    discuz网站前端代码优化思路
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5427249.html
Copyright © 2011-2022 走看看