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\n",dp[x]);
}
int main()
{
pre();
int t;scanf("%d",&t);
while(t--)solve();
return 0;
}

HDU 5673 Robot 数学的更多相关文章

  1. HDU 5673 Robot【卡特兰数】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5673 题意: 有一个机器人位于坐标原点上.每秒钟机器人都可以向右移到一个单位距离,或者在原地不动.如 ...

  2. hdu 5673 Robot 卡特兰数+逆元

    Robot Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem D ...

  3. HDU 5673 Robot ——(卡特兰数)

    先推荐一个关于卡特兰数的博客:http://blog.csdn.net/hackbuteer1/article/details/7450250. 卡特兰数一个应用就是,卡特兰数的第n项表示,现在进栈和 ...

  4. HDOJ(HDU).1035 Robot Motion (DFS)

    HDOJ(HDU).1035 Robot Motion [从零开始DFS(4)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DF ...

  5. hdu 4593 Robot

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4593 Robot Description A robot is a mechanical or vir ...

  6. HDU 4576 Robot (概率DP)

    暴力DP求解太卡时间了...........写挫一点就跪了 //hdu robot #include <cstdio> #include <iostream> #include ...

  7. HDU 3150 Robot Roll Call – Cambot…Servo…Gypsy…Croooow(map)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3150 Problem Description Mystery Science Theater 3000 ...

  8. HDU 5914 Triangle 数学找规律

    Triangle 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Description Mr. Frog has n sticks, who ...

  9. HDU 2493 Timer 数学(二分+积分)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2493 题意:给你一个圆锥,水平放置,圆锥中心轴与地面平行,将圆锥装满水,在圆锥某一表面开一个小洞,流出来 ...

随机推荐

  1. 转: oracle中schema指的是什么?

    看来有的人还是对schema的真正含义不太理解,现在我再次整理了一下,希望对大家有所帮助. 我们先来看一下他们的定义:A schema is a collection of database obje ...

  2. 56.Merge Intervals---贪心---《编程之美》2.19区间重合判断

    题目链接:https://leetcode.com/problems/merge-intervals/description/ 题目大意:给出一串list,里面装interval类,这个类里有star ...

  3. Docker practice

    Docker 实践 目标 创建一个基于最新版Ubuntu的镜像,在该镜像中更新apt包源并安装NTP package,最后将该新镜像提交到本地私有的registry中. 本地创建私有Registry ...

  4. AttributeError: 'str' object has no attribute 'decode'

    ue = e.decode('latin-1')修改为: ue = e.encode('ascii', 'strict')

  5. php pdo封装类

    class MYPDO { protected static $_instance = null; protected $dbname = ''; protected $dsn; protected ...

  6. poj 1041(字典序输出欧拉回路)

    John's trip Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8641   Accepted: 2893   Spe ...

  7. web2.0 HW3 相关阅读材料

    W3C官网的材料简直看花眼……除了挂出的文档,www-style@w3.org的一堆邮件也藏着很多宝,但是看下来又眼花了……(好在宝们基本都被W3C吸收了=.=) 主要来自W3C的官网w3.org的一 ...

  8. Python全栈开发之1、输入输出与流程控制

    Python简介 python是吉多·范罗苏姆发明的一种面向对象的脚本语言,可能有些人不知道面向对象和脚本具体是什么意思,但是对于一个初学者来说,现在并不需要明白.大家都知道,当下全栈工程师的概念很火 ...

  9. ubuntu 依赖问题

    ubuntu想装个QQ,无奈安装不但出错,还导致现在的软件依赖出了问题 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 您也许需要运行“apt --fix-b ...

  10. Java经典设计模式之七大结构型模式

    转载: Java经典设计模式之七大结构型模式 博主在大三的时候有上过设计模式这一门课,但是当时很多都基本没有听懂,重点是也没有细听,因为觉得没什么卵用,硬是要搞那么复杂干嘛.因此设计模式建议工作半年以 ...