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. Wireshark过滤语句中常用的操作符

    关键字有: eq,== 等于ne,!= 不等于gt,> 比…大lt,< 比…小 ge,>= 大于等于le,<= 小于等于 and,|| 且 or,&& 或 no ...

  2. C++之 extern C的作用详解

    extern "C"的主要作用就是为了能够正确实现C++代码调用其他C语言代码.加上extern "C"后,会指示编译器这部分代码按C语言的进行编译,而不是C+ ...

  3. Linux 添加普通用户到 sudoers 文件

    前言 Linux 的普通用户(uid >= 500)不具有某些命令的执行权限,为了执行较高权限的命令,一般有两种方法: 第一种是使用 su - 命令切换到 root 用户去执行: 另外一种方法是 ...

  4. 使用Git Wiki 管理文档时,文档编写的基本用法

    自己初次接触GitLab,通过百度和自己查找资料,了解了一部分.在自己的工作中,主要用到GitLab的Wiki文档版本管理能力.我总结了一小部分文本编辑需要用到的东西. 一.文本的排版 为了让文本/文 ...

  5. Webcollector应用(二)

    先吐槽一句哀家的人品,总在写好代码之后,网站默默的升级,没有一点点防备... 一.加代理 爬取一个网站的时候,爬了不到一半,IP被封了,整个内部局域网的所有电脑都不能访问网站了. public cla ...

  6. 欧拉回路&欧拉通路判断

    欧拉回路:图G,若存在一条路,经过G中每条边有且仅有一次,称这条路为欧拉路,如果存在一条回路经过G每条边有且仅有一次, 称这条回路为欧拉回路.具有欧拉回路的图成为欧拉图. 判断欧拉通路是否存在的方法 ...

  7. UVA 11624 Fire!(两次BFS+记录最小着火时间)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  8. Weex Workshop 挑战赛,等你来战!

    一个颠覆性的移动开发方式,一个匠心打造的跨平台移动开发工具,一个后App时代的生产力解放者—Weex,针对App Native开发频繁发版和多端研发的痛点,H5开发的页面稳定性.性能体验等问题,提供了 ...

  9. windows 下 nginx 配置虚拟主机

    1. 在 nginx 的配置文件 nginx.conf 里面 引入虚拟主机配置文件,以后所有的虚拟主机配置文件都在写这个文件里 include       vhost.conf; (或者新建vhost ...

  10. CVE-2010-3971 CSS内存破坏漏洞分析

    看了仙果版主的议题演讲,其中提到cve-2010-3971是一个浏览器漏洞利用中的里程碑.于是找来POC,尝试分析一下. 1.漏洞重现 XP SP3+ie6.0环境 poc如下: poc.htm &l ...