HEX 山东省第八届省赛D题
来源:互联网 发布:网络综合布线施工工序 编辑:程序博客网 时间:2024/05/16 15:34
HEX
Time Limit: 4000MS Memory Limit: 131072KB
Problem Description
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 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.
Input
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.
Output
For each case output one integer in a line, the number of ways to get to the destination MOD 1000000007.
Example Input
1 13 2100000 100000
Example Output
131
Hint
Author
“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
向左是(1,0)向右是(1,1)向下是(2,1)
有(1,1)+x(1,0)+y(2,1)+z(1,1)==(a,b);
z+y=b-1;
x+y=a-b;
然后循环一下y;表示出x,z;组合数
注意一下组合数的求法,小心TLE。
向左是(1,0)向右是(1,1)向下是(2,1)
有(1,1)+x(1,0)+y(2,1)+z(1,1)==(a,b);
z+y=b-1;
x+y=a-b;
然后循环一下y;表示出x,z;组合数
注意一下组合数的求法,小心TLE。
#include <cstdio>#include<algorithm>#include<cstring>#include<iostream>using namespace std;#define maxn 100007typedef long long ll;const int mod = 1e9+7;ll f[maxn];ll v[maxn];ll quick_pow(int a,int n){ long long tmp = a%mod; long long ans = 1; while(n) { if(n%2) { ans*= tmp; ans %= mod; } tmp *= tmp; tmp %= mod; n/=2; } return ans;}void init(){ f[0]=1; for(int i=1; i<maxn; i++) f[i] = (long long )(f[i-1] * i) % mod; for(int i=maxn-1; i>=0; i--) v[i] = quick_pow(f[i],mod-2) % mod;}ll C(int n,int m){ if(n==m || m == 0) return 1; return ( (long long) (f[n] * v[m]) % mod * v[n-m] %mod );}int main(){ int a,b; ll ans; init(); while(scanf("%d %d",&a,&b)!=EOF) { ans=0; int t=a-b;///x+y int k=b-1;///y+z int u=min(t,k); for(int i=0; i<=u; i++) { int o=t-i;///x int p=k-i;///z ans+=C(i+o+p,o)*C(i+p,i)%mod;///C(x+y+z,x)*C(y+z,y)*C(z,z) ans%=mod; } printf("%lld\n",ans); } return 0;}
阅读全文
0 0
- HEX 山东省第八届省赛D题
- 山东省第八届acm省赛D题 HEX
- HEX----组合数+逆元+思维 山东省第八届省赛D题
- hatuoj 1300 HEX----组合数+逆元+思维 山东省第八届省赛D题
- 山东省第八届ACM省赛 D.HEX
- 山东省第八届acm省赛D题HEX(组合数学)
- 2017山东省第八届ACM省赛 D. HEX(组合数学)
- 2017山东省-D-Hex
- HEX SDUT 3896 17年山东省赛D题
- 山东省第八届acm省赛 HEX
- 山东省第三届省赛D题
- CF----思维排序+01背包 山东省第八届省赛K题
- 山东省第八届省赛A题 Return of the Nim
- SDUT 3896 HEX 山东第八届ACM大赛D题(组合数学)
- 第八届山东省赛题->Parity check
- 第八届山东省赛题->CF
- 山东省第八届ACM省赛C题
- 山东省第八届ACM省赛A题
- 装饰器:动态修改类的功能
- More Effective C++之Item M9:使用析构函数防止资源泄漏
- ssh框架pom文件基本坐标_
- 开发一个WEB项目的流程
- dijkstra算法举栗子
- HEX 山东省第八届省赛D题
- JavaScript实现继承的几种方式
- 53. Maximum Subarray
- (10)Javascript入门三
- ThinkPHP 3.2 与 面向对象编程
- 网页语义化的个人理解
- 重哈希-LintCode
- maven 上传,下载所依赖的jar包
- android之图片(bitmap)总结 持续学习中......