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 ...
随机推荐
- Jquery中的ajax应用(第九章PPT)
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1&q ...
- 十个Chatbot框架介绍
十个Chatbot框架介绍 原创 2016年12月13日 16:01:23 4616 Chatbot列表 1. Artificial Intelligence Markup Language ...
- Unity GPU Query OpenGLES 3.0
https://github.com/google/render-timing-for-unity/blob/master/RenderTimingPlugin/RenderTimingPlugin. ...
- LeetCode(28)Implement strStr()
题目 Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if nee ...
- 【MySQL】海量量数据查询优化
参考资料: mysql处理海量数据时的一些优化查询速度方法:http://www.cnblogs.com/lingiu/p/3414134.html mysql千万级大数据SQL查询优化:http:/ ...
- chrome护眼模式
chrome护眼模式 使用stylish插件: 学习:https://jingyan.baidu.com/article/b907e627f74df146e6891c67.html 插件下载:http ...
- 最小生成树之Prim(普里姆)算法
关于什么是Prim(普里姆算法)? 在实际生活中,我们常常碰到类似这种一类问题:如果要在n个城市之间建立通信联络网, 则连通n个城市仅仅须要n-1条线路.这时.我们须要考虑这样一个问题.怎样在最节省经 ...
- Android开发之JNI(一)--HelloWorld及遇到的错误解析
Android开发之JNI(一)--HelloWorld及遇到的错误解析 1.NDK环境搭建 參考http://blog.csdn.net/xiaoliouc/article/details/8 ...
- hibernate hql 语句中 in 的用法
例子描述查询一些班级中的学生 /** * * @param city * @return */ public List<Student> studentList(final Integer ...
- Git学习资源推荐
Git在线练习 http://pcottle.github.io/learnGitBranching/ https://try.github.io/levels/1/challenges/1 Git入 ...