hdu5673 Robot 卡特兰数+组合数学+线性筛逆元
Robot
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 483 Accepted Submission(s): 244
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
The only line contains one integer n(1≤n≤1,000,000).
1
2
4
2
9
/**
题目: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 卡特兰数+组合数学+线性筛逆元的更多相关文章
- hdu5673 Robot 卡特兰数 / 默慈金数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5673 分析: 这道题是一道裸的默慈金数,比较容易想到的是用卡特兰数来做.不了解的可以先学习一下. 卡特 ...
- hdu 5673 Robot 卡特兰数+逆元
Robot Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem D ...
- 牛客网 牛客小白月赛1 I.あなたの蛙が帰っています-卡特兰数,组合数阶乘逆元快速幂
I.あなたの蛙が帰っています 链接:https://www.nowcoder.com/acm/contest/85/I来源:牛客网 这个题有点意思,是卡特兰数,自行百度就可以.卡特兰数用处 ...
- uva 1478 - Delta Wave(递推+大数+卡特兰数+组合数学)
option=com_onlinejudge&Itemid=8&category=471&page=show_problem&problem=4224" st ...
- Train Problem II(卡特兰数 组合数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023 Train Problem II Time Limit: 2000/1000 MS (Java/ ...
- 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 ...
- bzoj 3823: 定情信物 线性筛逆元
3823: 定情信物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 108 Solved: 2[Submit][Status] Descriptio ...
- [HNOI2009]有趣的数列(卡塔兰数,线性筛)
[HNOI2009]有趣的数列 题目描述 我们称一个长度为2n的数列是有趣的,当且仅当该数列满足以下三个条件: (1)它是从1到2n共2n个整数的一个排列{ai}: (2)所有的奇数项满足a1< ...
- BZOJ1856:[SCOI2010]字符串(卡特兰数,组合数学)
Description lxhgww最近接到了一个生成字符串的任务,任务需要他把n个1和m个0组成字符串,但是任务还要求在组成的字符串中,在任意的前k个字符中,1的个数不能少于0的个数.现在lxhgw ...
随机推荐
- 解密所有APP运行过程中的内部逻辑(转)
转贴地址:http://www.freebuf.com/tools/54562.html 0×01前言 这年头,apk 全都是加密啊,加壳啊,反调试啊,小伙伴们表示已经不能愉快的玩耍了.静态分析越来越 ...
- How to Analyze "Deadlocked Schedulers" Dumps?---WINDBG
https://blogs.msdn.microsoft.com/karthick_pk/2010/06/22/how-to-analyze-deadlocked-schedulers-dumps/ ...
- win8.1无法安装安装.net framework 3.5 解决办法【转】
安装流程1.以系统管理员开启命令提示符(命令提示字符)2挂载windows8.1异3,在命令提示符下输入Dism /online /enablefeature/featurename:NetFx3 / ...
- GSM模块_GPRS数据传输机制和原理
通信专业术语 BSS--基站子系统,通过无线接口与移动台直接联系,负责在一定区域内和移动台通信.(GSM) BTS--基站收发台,可以看作一复杂的无线调制器,BSS的主要部分,每个分配有若干信道.(G ...
- Java集合迭代器 Iterator分析
简介 迭代器是遍历容器的一种常用方法,它屏蔽了容器的实现细节,无需暴露数据结构内部,就可以对容器进行遍历,迭代器本身也是一种设计模式,迭代是一种特殊的遍历方式. Iterator 在java中,迭代器 ...
- centos7 minimal connect: Network is unreachable(转)
新装的centos7,果然是很崭新啊. 装好之后打算看一下局域网的地址,然后就ip addr(centos 7 已经去掉了ifconfig这个命令).并没有显示局域网的ip地址. 然后我尝试ping ...
- javascript - 闭包以及函数
/** * 匿名函数 */ (function () { /** * 是否启用跟踪用户隐私 * * 启用:isPrivacys(true) * 不启用:isPrivacys(false) * */ f ...
- C 实现strcmp,strcpy,strcat函数
基于C语言的strcmp,strcpy,strcat函数的实现.C语言是一个程序猿的基础,一定要重视. char* strcat ( char * dst , const char * src ) { ...
- How to get the url of a page in OpenERP?
How to get the url of a page in OpenERP? User is using OpenERP. I have a button on one web page. The ...
- javascript 捕获异常方法
捕获异常的实例: var str="fasdfsadfsad$$异常信息$$你看不到我"; var arr=str.split("$$"); arr[1]; 通 ...