Robot

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

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
思路:把n步当成最多往右走[n/2]步,最多往左走[n/2]步,当成火车出栈和入栈,卡特兰数,枚举到[n/2];
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pi (4*atan(1.0))
  5. #define eps 1e-14
  6. const int N=2e5+,M=4e6+,inf=1e9+,mod=1e9+;
  7. const ll INF=1e18+;
  8. ll a[M];
  9. ll inv[M];
  10. void init()
  11. {
  12. inv[] = ;
  13. for(int i=;i<=;i++)
  14. {
  15. if(i >= mod)break;
  16. inv[i] = (mod - mod / i) * inv[mod % i]% mod;
  17. }
  18. }
  19. ll c[M];
  20. int main()
  21. {
  22. a[]=;
  23. init();
  24. for(ll i=;i<=;i++)
  25. {
  26. a[i]=(((a[i-]*(*i-))%mod)*inv[i+])%mod;
  27. }
  28. int T,cas=;
  29. scanf("%d",&T);
  30. while(T--)
  31. {
  32. int n;
  33. scanf("%d",&n);
  34. c[]=;
  35. for(int i=,t=n;i<=n;t--,i++)
  36. {
  37. c[i]=(((c[i-]*t)%mod)*inv[i])%mod;
  38. }
  39. ll ans=;
  40. for(int i=;i*<=n;i++)
  41. {
  42. ans=(ans+(a[i]*c[*i])%mod)%mod;
  43. }
  44. printf("%lld\n",ans);
  45. }
  46. return ;
  47. }

hdu 5673 Robot 卡特兰数+逆元的更多相关文章

  1. hdu 5184 类卡特兰数+逆元

    BC # 32 1003 题意:定义了括号的合法排列方式,给出一个排列的前一段,问能组成多少种合法的排列. 这道题和鹏神研究卡特兰数的推导和在这题中的结论式的推导: 首先就是如何理解从题意演变到卡特兰 ...

  2. hdu 4828 Grids 卡特兰数+逆元

    Grids Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Problem D ...

  3. HDU 5673 Robot【卡特兰数】

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

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

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

  5. hdu5673 Robot 卡特兰数+组合数学+线性筛逆元

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

  6. HDU 4828 (卡特兰数+逆元)

    HDU 4828 Grids 思路:能够转化为卡特兰数,先把前n个人标为0,后n个人标为1.然后去全排列,全排列的数列,假设每一个1的前面相应的0大于等于1,那么就是满足的序列.假设把0看成入栈,1看 ...

  7. hdu5673 Robot 卡特兰数 / 默慈金数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5673 分析: 这道题是一道裸的默慈金数,比较容易想到的是用卡特兰数来做.不了解的可以先学习一下. 卡特 ...

  8. hdu 5184(数学-卡特兰数)

    Brackets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  9. hdu_4828_Grids(卡特兰数+逆元)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4828 题意:中文,不解释 题解:实际就是一个卡特兰递推: Catalan(n+1)= Catalan( ...

随机推荐

  1. gerrit docker运行失败 chown: /var/gerrit/review_site: Permission denied 【已解决】

    Docker Volume 之权限管理(转) - jackluo - 博客园 http://www.cnblogs.com/jackluo/p/5783116.html 为什么在公司电脑没有问题,但在 ...

  2. Serializable 序列化

    序列化是指将对象实例的状态存储到存储媒体的过程.在此过程中,先将对象的公共字段和私有字段以及类的名称(包括类所在的程序集)转换为字节流,然后再把字节流写入数据流.在随后对对象进行反序列化时,将创建出与 ...

  3. php ssh2 scp问题解决

    <?php$connection = ssh2_connect('192.168.1.XX', 22);$res=ssh2_auth_password($connection, 'root', ...

  4. 分析Linux内核创建一个新进程的过程【转】

    转自:http://www.cnblogs.com/MarkWoo/p/4420588.html 前言说明 本篇为网易云课堂Linux内核分析课程的第六周作业,本次作业我们将具体来分析fork系统调用 ...

  5. Android Studio解决unspecified on project app resolves to an APK archive which is not supported

    出现该问题unspecified on project app resolves to an APK archive which is not supported as a compilation d ...

  6. python7 静态方法、类方法、属性方法 ;反射;异常处理

      #-*- coding:utf8 -*- # 静态方法@staticmethod # 静态方法(当eat变成静态方法后,再通过实例调用时就不会自动把实例本身当作一个参数传给self了.) clas ...

  7. c3p0数据库连接池(作用不重复)

    /* * c3p0数据库连接池: * 只被初始化一次 * connection对象进行close时,不是正的关闭,而是将该数据连接归还给数据库连接池 * * */ 四个架包 mysql-connect ...

  8. MultiSelectComboBox(二)

    1. MainWindow.xaml <Window x:Class="MultiSelectDemo.MainWindow"         xmlns="htt ...

  9. 多校5-MZL's Border 分类: 比赛 2015-08-05 21:28 7人阅读 评论(0) 收藏

    MZL's Border Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...

  10. POI 简单合并单元格

    public class MergedCells { /** 测试使用的POI版本是3.1 * @param args */ public static void main(String[] args ...