【默慈金数+求逆元】HDU5673Robot【BestCoder Round #81 (div.2)】
来源:互联网 发布:淘宝网店怎么有生意 编辑:程序博客网 时间:2024/05/29 19:21
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5673
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 aftern seconds the robot is still located on the origin point?
The answer may be large. Please output the answer modulo1,000,000,007
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
The answer may be large. Please output the answer modulo
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 integern(1≤n≤1,000,000) .
The only line contains one integer
Output
For each test case, output one integer.
Sample Input
3124
Sample Output
129
数论啊数论。。。。
首先,必须知道这是个默慈金数的模板题,知道是模板题之后,因为是取模,所以我们直接可以用long long 型来解决问题,但是需要注意的是,不能用除法,所以这里我们就又学到了一点,那就是逆元。日后来好好整理orz........
代码:
#include<iostream>#define LL long long#define mod 1000000007using namespace std;const int N=1e6+5;LL M[N],inv[N];int main(){ int t,n; inv[1]=1; // 求逆元 for(int i=2;i<N;i++){ inv[i]=(mod-mod/i)*inv[mod%i]%mod; } M[0]=1; M[1]=1; // 求默慈金数 for(int i=2;i<=N-5;i++){ LL m1=M[i-1]*(2*i+1)%mod; LL m2=(3*i-3)*M[i-2]%mod; M[i]=(m1+m2)%mod*inv[i+2]%mod; // 这里直接除法,有问题,这里我们需要用到逆元 } cin.sync_with_stdio(false); cin>>t; while(t--){ cin>>n; cout<<M[n]<<endl; } return 0;}
0 0
- 【默慈金数+求逆元】HDU5673Robot【BestCoder Round #81 (div.2)】
- BestCoder Round #81 (div.2)
- BestCoder Round #81 (div.2)
- BestCoder Round #81 (div.2) Machine
- BestCoder Round #81 (div.2):1001 Machine
- BestCoder Round #81 (div.2) CC String
- BestCoder Round #81 (div.2)A
- 【BestCoder Round #81 (div.2)】HDU5670Machine
- 【BestCoder Round #81 (div.2)】HDU5671Matrix
- BestCoder Round #11 (Div. 2)
- BestCoder Round #11 (Div. 2)
- BestCoder Round #50 (div.2)
- BestCoder Round #50 (div.2)
- BestCoder Round 50 (div 2)
- BestCoder Round #50 (div.2)
- #BestCoder Round #50 (div.2)
- BestCoder Round #50 (div.2)
- BestCoder Round #54 (div.2)
- 湖南第九届省赛 字符识别
- Aptana Studio 3.0插件版
- main函数的参数
- 解决sudo status docker命令出错的问题
- 使用errno.h示例
- 【默慈金数+求逆元】HDU5673Robot【BestCoder Round #81 (div.2)】
- day63-Spark SQL下Parquet内幕深度解密
- BM算法模式匹配——字符串与KMP比较
- struts2(七)输入校验
- 学些HTML5的一些小记
- tomcat(supplement)HttpConnector.initialize() 和 start() 方法 以及 StandardContext.start()方法的分析
- 用windows下的上帝模式隐藏文件
- 计算机网络,网络层
- 湖南第十届省赛 Double Shortest Paths