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 ;
}

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. [转]从此爱上iOS Autolayout

    原文地址 这篇不是autolayout教程,只是autolayout动员文章和经验之谈,在本文第五节友情链接和推荐中,我将附上足够大家熟练使用autolayout的教程.这篇文章两个月前就想写下来,但 ...

  2. @RequestMapping注解的使用,Controller方法返回值

    1,web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=" ...

  3. python 实现汉诺塔问题

    代码如下: def hano(n,x,y,z): if n==1: print(x,"->",z) else: #将n-1个盘子从x->y hano(n-1,x,z,y ...

  4. LongPathException问题解析

    一.背景      当windows系统下使用System.IO命名空间下的方法,目录长度超过260个字符时,.net framework会抛出LongPathException.查阅相关资料,发现是 ...

  5. ldr与adr的区别

    参考: http://coon.blogbus.com/logs/2738861.html http://hi.baidu.com/for_guanghui/item/73e60bbcc8be15a2 ...

  6. Visual Studio 控制台应用程序 同时使用OpenCV和matlab mat文件操作

    matalb具有灵活的图像处理,代码编写起来简洁而高效.而OpenCV具有很多成熟的计算机视觉算法,能够处理很多实时的识别处理等问题,而且代码运行起来效率很高.所以如何结合两者之间的优点,是让很多学术 ...

  7. asp.net mvc视图引擎

    继上周介绍了Razor之后,ASP.NET MVC 现在已有四种主要的视图引擎.其他三种引擎是Spark.NHaml和传统的ASPX文件模板.本文将大致介绍这四种引擎,并着重讨论新的Razor引 擎. ...

  8. linux 逻辑卷管理 调整分区大小

    测试机各种报错,创建个目录都报错,df看了一下,发现VolGroup-lv_root 100%,虚拟磁盘满了,怎么办呢 1,解决过程 # df -h //查看分区 # umount /home //取 ...

  9. javascript快速入门17--事件

    事件(上) JavaScript事件列表 事件 解说 一般事件 onclick 鼠标点击时触发此事件 ondblclick 鼠标双击时触发此事件 onmousedown 按下鼠标时触发此事件 onmo ...

  10. 利用JS实现在li中添加或删除class属性

    $( function() { $("#test li").click(function(){ $("#test li").removeClass(" ...