hatuoj 1300 HEX----组合数+逆元+思维 山东省第八届省赛D题
来源:互联网 发布:黑帽seo基础 编辑:程序博客网 时间:2024/06/05 20:51
问题 1300. – HEX
1300: HEX
时间限制: 4 秒 内存限制: 128 MB提交: 26 解决: 9
提交 状态
题目描述
On a plain
of hexagonal grid, we define a step as one move from the current grid to the
lower/lower-left/lower-right grid. For example, we can move from (1,1) to
(2,1), (2,2) or (3,2).
In thefollowing graph we give a demonstrate of how this coordinate system works.
Your taskis to calculate how many possible ways can you get to grid(A,B) from gird(1,1),where A and B represent the grid is on the B-th position of the A-th line.
输入
For each test case, two integers A
(1<=A<=100000) and B (1<=B<=A) are given in a line, process till
the end of file, the number of test cases is around 1200.
输出
each case output one integer in a line, the number of ways to get to the
destination MOD 1000000007.
样例输入
1 1
3 2
100000 100000
样例输出
1
3
1
提示
来源
题意 就是从 1,1开始每次向 ↙ ↓ ↘这几个方向移动,给一个坐标,问到那个点有多少种走法
这肯定是排列组合题目,先把到一个点向左向右走的步数算出来,向左就是 n-m 向右是 m-1 (大佬推出来的规律) ,设 C是竖着走的步数,则走到一个点需要 l+r+c步 ,先把向左向右走看成一个 C(l+r+c,c)(向左向右走的所有情况的个数)这就是 C(l+r+c,c) C(l+r,r)就是所有情况,然后枚举c就可以了
看的大佬的博客都是(l+r+c) ! / ( l! * r! c!) 就是 C(l+r+c,c) C(l+r,r)化简的结果,会减一半时间
注意 除法取余 逆元(需打表,要不会超时)
#include<bits/stdc++.h>using namespace std;#define mod 1000000007#define ll long longll re[100009];ll vi[100009];ll poww(ll a,ll b){ ll ans=1; while(b) { if(b&1) ans=(ans*a)%mod; b>>=1; a=(a*a)%mod; } return ans;}void intt(){ re[0]=1; vi[0]=1; for(int i=1;i<=100003;i++) { re[i]=(i*re[i-1])%mod; vi[i]=poww(re[i],mod-2)%mod; //cout<<vi[i]<<endl; }}ll C(int a,int b){ return (re[a]*(vi[a-b]%mod*vi[b]%mod)%mod)%mod;}int main(){ // ios::sync_with_stdio(false); ll n,m; intt(); while(cin>>n>>m) { ll ans=0; //int i=m; int l=n-m,r=m-1; int c=0; // int k=l+r-1; while(l>=0&&0<=r) { ans+=C(l+r+c,c)*C(l+r,r)%mod; // ans+=re[l+r+c]*(vi[l]%mod*vi[r]%mod*vi[c]%mod)%mod; ans%=mod; c++; l--; r--; } cout<<ans<<endl; } return 0;}
- hatuoj 1300 HEX----组合数+逆元+思维 山东省第八届省赛D题
- HEX----组合数+逆元+思维 山东省第八届省赛D题
- HEX 山东省第八届省赛D题
- 2017山东省第八届ACM省赛 D. HEX(组合数学)
- 山东省第八届acm省赛D题HEX(组合数学)
- 山东省第八届acm省赛D题 HEX
- 山东省第八届ACM省赛 D.HEX
- 第八届山东省赛 C sdut 3895 fireworks(组合数+逆元)
- 山东省第八届 ACM 省赛 fireworks (组合数+逆元)
- sdutoj 3896 HEX 思维+组合数
- 2017山东省-D-Hex
- codeforces 816 D. Karen and Test(逆元+思维+组合数
- 2017山东省赛D题(SDUT3896逆元法求组合数)
- CF----思维排序+01背包 山东省第八届省赛K题
- SDUT 3896 HEX 山东第八届ACM大赛D题(组合数学)
- HEX SDUT 3896 17年山东省赛D题
- 端午节个人赛-山东省省赛 fireworks(杨辉三角形+组合数+逆元)
- Fireworks(山东省第8届ACM省赛)逆元,组合数
- maven快速入门 下搭建javaWeb工程
- DES算法概述
- redis高可用分布式集群
- 搬瓦工安装ngrok的服务器端,兼容ngrok-libev客户端
- 嵌入式调试器GDB调试过程
- hatuoj 1300 HEX----组合数+逆元+思维 山东省第八届省赛D题
- 第四章 变量、作用域和内存问题
- 机房收费系统篇(一)
- 贝叶斯分类器
- 十六进制转十进制
- 語言編碼
- python常量与变量
- 嵌套if-else与多重~
- PyCharm激活码2017