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. php常用函数——数组函数

    php常用函数——数组函数

  2. sqlmap tamper编写

    #!/usr/bin/env python """ Copyright (c) 2006-2017 sqlmap developers (http://sqlmap.or ...

  3. [转载]Windows服务编写原理及探讨(2)

    (二)对服务的深入讨论之上 上一章其实只是概括性的介绍,下面开始才是真正的细节所在.在进入点函数里面要完成ServiceMain的初始化,准确点说是初始化一个 SERVICE_TABLE_ENTRY结 ...

  4. css3动画详解

    一.Keyframes介绍: Keyframes被称为关键帧,其类似于Flash中的关键帧.在CSS3中其主要以“@keyframes”开头,后面紧跟着是动画名称加上一对花括号“{…}”,括号中就是一 ...

  5. Hashtable之Properties

    properties的使用:1.Hashtable的实现类,线程安全.与HashMap不同,Hashtable不允许使用null作为key和value2.和HashMap一样,Hashtable也不能 ...

  6. 正排索引(forward index)与倒排索引(inverted index) (转)

    一.正排索引(前向索引) 正排索引也称为"前向索引".它是创建倒排索引的基础,具有以下字段. (1)LocalId字段(表中简称"Lid"):表示一个文档的局部 ...

  7. List基本用法

    List最为Collection接口的子接口,当然可以使用Collection接口里的全部方法.而且由于List是有序集合,因此List集合里增加了一些根据索引来操作集合元素的方法: public c ...

  8. NIO-1缓冲区(Buffer)

    import java.nio.ByteBuffer; import org.junit.Test; /* * 一.缓冲区(Buffer):在 Java NIO 中负责数据的存取.缓冲区就是数组.用于 ...

  9. 编辑器之Sublime Text3、Notepad++

    Sublime text 3 破解版是一款极其强大的代码编辑器,又是一款可以代替记事本的文本编辑器.Sublime text 3拥有着美观的界面和实用的功能,既能够完成代码的编辑又能够完成文本编辑,还 ...

  10. Jenkins架构

    一. Master 和slave. 下图阐述了master-slave交互的架构: