Robot

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 483    Accepted Submission(s): 244

Problem 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
 
Source
 
/**
题目:Robot
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5673
题意:在x轴上,机器人从原点出发,如果它在原点,他只可以向右走一格,或者停留原处(表明机器人不可以到负数坐标的位置);
如果不在原点,它可以向右,向左,停留原地;每次操作花费1秒;问n秒后,机器人回到原点的行走方法数; 思路:
过程中一定是向右走的步数>=向左走的步数,最后是相等。想到了什么?括号匹配? 求方法数->卡特兰数。
现在还有一个是停在原地。设停在原地为y次。向右走为x次,那么向左走也为x次。
2*x+y==n;
那么确定了x,y。方法数:C(n,y)*h(x). 很显然; */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int mod=1e9+;
const int maxn=1e6+;
LL h[maxn], c[maxn], inv[maxn];
void init()
{
inv[] = ;
for(int i = ; i < maxn; i++){
inv[i] = (mod-mod/i)*inv[mod%i]%mod;
}
h[] = ;
for(int i = ; i < maxn; i++){
h[i] = (*i-)*h[i-]%mod*inv[i+]%mod;
}
}
int main()
{
init();
int T;
int n;
cin>>T;
while(T--)
{
scanf("%d",&n);
LL ans = ;
c[] = ;
for(int i = ; i <= n; i++){///c(n,i);
c[i] = (n-i+)*c[i-]%mod*inv[i]%mod;
}
for(int x = ; x*<=n; x++){
int y = n-*x;
ans = (ans+c[y]*h[x]%mod)%mod;
}
printf("%lld\n",ans);
}
return ;
}

最新文章

  1. 特大喜讯,View and Data API 现在支持中文界面了
  2. Java并发之原子变量和原子引用与volatile
  3. SQL Server 更改跟踪(Chang Tracking)监控表数据
  4. bootstrap-简洁实用的jQuery手风琴插件
  5. JMS links
  6. Windows server 修改mysql端口
  7. 快速学习C语言四: 造轮子,ArrayList
  8. 什么是CGI
  9. Android 二维码 生成和识别(转)
  10. 【翻译十三】java-并发之饥饿与活锁
  11. ANTLR3完全参考指南读书笔记[08]
  12. hdu 1548 (dijkstra解法)(一次AC就是爽)
  13. C语言中的三字母词
  14. mssql 用户只能查看授权的数据库
  15. MySql实现远程连接
  16. OMCS的语音视频带宽占用
  17. 关于 调用 JNI JAR 的说明和注意事项,调用第三方 JAR SDK 和 翻译 安卓 JAVA 代码 的说明 V2015.6.10
  18. java通过数据库连接池链接oracle
  19. Python randrange() 函数
  20. python全栈开发 * 14 知识点汇总 * 180530

热门文章

  1. 如何让Adobe reader 记住上次pdf文档打开位置?
  2. 自定义PHP页面跳转函数redirect($url, $time = 0, $msg = &#39;&#39;)
  3. Could not instantiate bean class [org.springframework.data.domain.Pageable]: Specified class is an interface解决方案
  4. Coherence的NameService
  5. scrapy安装使用教程
  6. Echart学习
  7. python socket timeout设置
  8. iOS: 格式化新浪微博/QQ说说等等的发布时间
  9. 如何看待Linux操作系统的用户空间和内核空间
  10. windows下curl报错:curl : (1) Protocol https not supported or disabled in libcurl