hatuoj 1300 HEX----组合数+逆元+思维 山东省第八届省赛D题
2017-10-02 17:38
381 查看
问题 1300. – HEX
提交: 26 解决: 9
提交 状态
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 the
following graph we give a demonstrate of how this coordinate system works.
Your task
is 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.
(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开始每次向 ↙ ↓ ↘这几个方向移动,给一个坐标,问到那个点有多少种走法
这肯定是排列组合题目,先把到一个点向左向右走的步数算出来,向左就是 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)化简的结果,会减一半时间
注意 除法取余 逆元(需打表,要不会超时)
1300: HEX
时间限制: 4 秒 内存限制: 128 MB提交: 26 解决: 9
提交 状态
题目描述
On a plainof 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 the
following graph we give a demonstrate of how this coordinate system works.
Your task
is 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.
输出
Foreach 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 long ll 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; }
相关文章推荐
- HEX----组合数+逆元+思维 山东省第八届省赛D题
- 2017山东省第八届ACM省赛 fireworks(杨辉三角 + 逆元)
- 2017山东省第八届ACM省赛 D. HEX(组合数学)
- Fireworks(山东省第8届ACM省赛)逆元,组合数
- 山东省第八届省赛 sdut 3896(找规律+组合数取模)
- 山东省第八届 ACM 省赛 fireworks (组合数+逆元)
- fireworks 2017年山东省ACM省赛C题 SDUT 3895 (逆元求组合数)
- 山东省第八届ACM省赛 D.HEX
- 山东省第八届acm省赛D题 HEX
- CF----思维排序+01背包 山东省第八届省赛K题
- 山东省第八届acm省赛D题HEX(组合数学)
- 山东省第八届acm省赛 HEX
- HEX 山东省第八届省赛D题
- 第八届山东省赛 C sdut 3895 fireworks(组合数+逆元)
- 2017年山东省第八届ACM大学生程序设计竞赛 C fireworks(sdut 3895) 逆元求组合数
- 山东省第八届ACM省赛 F 题(quadratic equation)
- 山东省第八届ACM省赛 G 题 sum of power 解答
- 山东省第八届ACM省赛 I 题(Parity check)
- 端午节月赛-山东省第八届省赛 Parity check(找奇偶规律)
- 山东省第八届ACM省赛 I 题 Parity check 详解