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
 
  1. /**
  2. 题目:Robot
  3. 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5673
  4. 题意:在x轴上,机器人从原点出发,如果它在原点,他只可以向右走一格,或者停留原处(表明机器人不可以到负数坐标的位置);
  5. 如果不在原点,它可以向右,向左,停留原地;每次操作花费1秒;问n秒后,机器人回到原点的行走方法数;
  6.  
  7. 思路:
  8. 过程中一定是向右走的步数>=向左走的步数,最后是相等。想到了什么?括号匹配? 求方法数->卡特兰数。
  9. 现在还有一个是停在原地。设停在原地为y次。向右走为x次,那么向左走也为x次。
  10. 2*x+y==n;
  11. 那么确定了x,y。方法数:C(n,y)*h(x). 很显然;
  12.  
  13. */
  14. #include <iostream>
  15. #include <cstdio>
  16. #include <cstring>
  17. #include <algorithm>
  18. using namespace std;
  19. typedef long long LL;
  20. const int mod=1e9+;
  21. const int maxn=1e6+;
  22. LL h[maxn], c[maxn], inv[maxn];
  23. void init()
  24. {
  25. inv[] = ;
  26. for(int i = ; i < maxn; i++){
  27. inv[i] = (mod-mod/i)*inv[mod%i]%mod;
  28. }
  29. h[] = ;
  30. for(int i = ; i < maxn; i++){
  31. h[i] = (*i-)*h[i-]%mod*inv[i+]%mod;
  32. }
  33. }
  34. int main()
  35. {
  36. init();
  37. int T;
  38. int n;
  39. cin>>T;
  40. while(T--)
  41. {
  42. scanf("%d",&n);
  43. LL ans = ;
  44. c[] = ;
  45. for(int i = ; i <= n; i++){///c(n,i);
  46. c[i] = (n-i+)*c[i-]%mod*inv[i]%mod;
  47. }
  48. for(int x = ; x*<=n; x++){
  49. int y = n-*x;
  50. ans = (ans+c[y]*h[x]%mod)%mod;
  51. }
  52. printf("%lld\n",ans);
  53. }
  54. return ;
  55. }

hdu5673 Robot 卡特兰数+组合数学+线性筛逆元的更多相关文章

  1. hdu5673 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. 牛客网 牛客小白月赛1 I.あなたの蛙が帰っています-卡特兰数,组合数阶乘逆元快速幂

    I.あなたの蛙が帰っています   链接:https://www.nowcoder.com/acm/contest/85/I来源:牛客网     这个题有点意思,是卡特兰数,自行百度就可以.卡特兰数用处 ...

  4. uva 1478 - Delta Wave(递推+大数+卡特兰数+组合数学)

    option=com_onlinejudge&Itemid=8&category=471&page=show_problem&problem=4224" st ...

  5. Train Problem II(卡特兰数 组合数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023 Train Problem II Time Limit: 2000/1000 MS (Java/ ...

  6. CodeForces - 896D :Nephren Runs a Cinema(卡特兰数&组合数学---比较综合的一道题)

    Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema. Howev ...

  7. bzoj 3823: 定情信物 线性筛逆元

    3823: 定情信物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 108  Solved: 2[Submit][Status] Descriptio ...

  8. [HNOI2009]有趣的数列(卡塔兰数,线性筛)

    [HNOI2009]有趣的数列 题目描述 我们称一个长度为2n的数列是有趣的,当且仅当该数列满足以下三个条件: (1)它是从1到2n共2n个整数的一个排列{ai}: (2)所有的奇数项满足a1< ...

  9. BZOJ1856:[SCOI2010]字符串(卡特兰数,组合数学)

    Description lxhgww最近接到了一个生成字符串的任务,任务需要他把n个1和m个0组成字符串,但是任务还要求在组成的字符串中,在任意的前k个字符中,1的个数不能少于0的个数.现在lxhgw ...

随机推荐

  1. Qemu 有用的链接

    Qemu下载和编译 Download https://en.wikibooks.org/wiki/QEMU/Linux https://en.wikibooks.org/wiki/QEMU/Insta ...

  2. redis push/pop(List)的17条命令

    一.Blpop 命令移出并获取列表的第一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止.redis 127.0.0.1:6379> BLPOP LIST1 LIST2 .. ...

  3. XSS跨站脚本测试用例

    '><script>alert(document.cookie)</script>='><script>alert(document.cookie)&l ...

  4. BSP

    1       BSP概述 BSP即Board Support Package,板级支持包.它来源于嵌入式操作系统与硬件无关的设计思想,操作系统被设计为运行在虚拟的硬件平台上.对于具体的硬件平台,与硬 ...

  5. 一起來玩鳥 Starling Framework(6)Juggler、Tween、以及DelayCall

    這篇開始來講Starling裡的Animation.Juggle是個簡單的Class,用來控制動畫的進行.他負責管理經由add()加進來的實現IAnimatable介面的物件,然後當Juggler的a ...

  6. 【CloudFoundry】架构、设计参考

    参考资料: Cloud Foundry:http://baike.baidu.com/link?url=eIfPiUI8UlsqwnnSmmZ-WFyzrf38P33lJae4Hipsd0ynwXZp ...

  7. JavaScript 数字与字符串 比较大小

    总结一下JS中经常遇到纯数字和各种各样的字符串进行比较: 纯数字之间的比较 alert(1<3);//true 数字字符串比较,会将其先转成数字 alert("1"<& ...

  8. C#秘密武器之泛型

    一.简介: 很多初学者在刚开始接触泛型的时候会比较难理解泛型,在这里先把 “泛型”当作一个形容词,这样就方便理解了,因为很多东西都可以是泛型的!比如:“泛型的类”,“泛型的方法”,“泛型的接口”,“泛 ...

  9. Ios 调用Appstore 下载界面 [[UIApplication sharedApplication] openURL

    http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?mt=8&id=286274367 id = itunesconn ...

  10. git 基于某个分支创建分支

    1.拷贝源代码 git clone git@git地址 cd 项目目录 2.根据已有分支创建新的分支 git checkout -b yourbranchname origin/oldbranchna ...