hdu 5673 Robot 卡特兰数+逆元
Robot
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
ll a[M];
ll inv[M];
void init()
{
inv[] = ;
for(int i=;i<=;i++)
{
if(i >= mod)break;
inv[i] = (mod - mod / i) * inv[mod % i]% mod;
}
}
ll c[M];
int main()
{
a[]=;
init();
for(ll i=;i<=;i++)
{
a[i]=(((a[i-]*(*i-))%mod)*inv[i+])%mod;
}
int T,cas=;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
c[]=;
for(int i=,t=n;i<=n;t--,i++)
{
c[i]=(((c[i-]*t)%mod)*inv[i])%mod;
}
ll ans=;
for(int i=;i*<=n;i++)
{
ans=(ans+(a[i]*c[*i])%mod)%mod;
}
printf("%lld\n",ans);
}
return ;
}
hdu 5673 Robot 卡特兰数+逆元的更多相关文章
- hdu 5184 类卡特兰数+逆元
BC # 32 1003 题意:定义了括号的合法排列方式,给出一个排列的前一段,问能组成多少种合法的排列. 这道题和鹏神研究卡特兰数的推导和在这题中的结论式的推导: 首先就是如何理解从题意演变到卡特兰 ...
- hdu 4828 Grids 卡特兰数+逆元
Grids Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Problem D ...
- HDU 5673 Robot【卡特兰数】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5673 题意: 有一个机器人位于坐标原点上.每秒钟机器人都可以向右移到一个单位距离,或者在原地不动.如 ...
- HDU 5673 Robot ——(卡特兰数)
先推荐一个关于卡特兰数的博客:http://blog.csdn.net/hackbuteer1/article/details/7450250. 卡特兰数一个应用就是,卡特兰数的第n项表示,现在进栈和 ...
- hdu5673 Robot 卡特兰数+组合数学+线性筛逆元
Robot Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- HDU 4828 (卡特兰数+逆元)
HDU 4828 Grids 思路:能够转化为卡特兰数,先把前n个人标为0,后n个人标为1.然后去全排列,全排列的数列,假设每一个1的前面相应的0大于等于1,那么就是满足的序列.假设把0看成入栈,1看 ...
- hdu5673 Robot 卡特兰数 / 默慈金数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5673 分析: 这道题是一道裸的默慈金数,比较容易想到的是用卡特兰数来做.不了解的可以先学习一下. 卡特 ...
- hdu 5184(数学-卡特兰数)
Brackets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- hdu_4828_Grids(卡特兰数+逆元)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4828 题意:中文,不解释 题解:实际就是一个卡特兰递推: Catalan(n+1)= Catalan( ...
随机推荐
- VMWare联网
VMWare提供了三种工作模式,它们是bridged(桥接模式).NAT(网络地址转换模式)和host-only(主机模式). 如果你想利用VMWare在局域网中新建一个独立的虚拟服务器,为局域网用 ...
- LUA之面向对象
Account = { balance=0, withdraw = function (self, v) self.balance = self.balance - v end } function ...
- Backup: Flow Control in Perl6
Control Flow 注意空格,注意空格,注意空格 和 Perl5不同的是,这些结构都可以返回值,而且即使倒置结构也可以用 block 了 block 可以有逗号 with without orw ...
- java map 遍历
转自http://rain-2372.iteye.com/blog/1615615 package com.spring.test_B11_aop1; import java.util.HashMap ...
- JavaEE基础(十)
1.面向对象(package关键字的概述及作用) A:为什么要有包 将字节码(.class)进行分类存放 包其实就是文件夹 B:包的概述 举例: 学生:增加,删除,修改,查询 老师:增加,删除,修改, ...
- Java可变长参数方法调用问题
不说废话,直接上代码: package mytest; import java.util.List; public class TestClass { public void method(List& ...
- hashMap底层put和get方法逻辑
1.hashmap put方法的实现: public V put(K key, V value) { if (key == null) return putForNullKey(value); int ...
- ACM题目————STL练习之 懒省事的小明(优先队列)
描述 小明很想吃果子,正好果园果子熟了.在果园里,小明已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.小明决定把所有的果子合成一堆. 因为小明比较懒,为了省力气,小明开始想点子了: 每一 ...
- prop
用法:prop(属性|key,value|fn) 用例:点击全选/取消全选 // 全选 和全不选 $("#check_all").click(function () { if ($ ...
- YTU 3020: 对称矩阵(数组)
3020: 对称矩阵(数组) 时间限制: 1 Sec 内存限制: 128 MB 提交: 3 解决: 2 题目描述 已知A和B为两个n*n阶的对称矩阵,输入时,对称矩阵只输入下三角行元素,存入一维数 ...