HEX
来源:互联网 发布:软件项目阶段性总结 编辑:程序博客网 时间:2024/05/16 14:49
HEX
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
存个代码,提示就是选路问题,有三个走法,下,下左,下右。用组合数学做
#include <bits/stdc++.h>using namespace std;const long long mod = 1e9+7;const int maxn = 1e5+10;typedef long long LL;LL fac[maxn],Ni[maxn];LL modxp(LL a,LL b,LL p){ LL res = 1; while(b){ if(b&1) res = (res*a)%p; b = b>>1; a = (a*a)%p; } return res;}LL niYuan(LL a, LL b){//费马小定理求逆元 return modxp(a, b - 2, b);}void Init(){ fac[0] = 1; Ni[0] = 1; for(int i = 1; i < maxn; i++){ fac[i] = (fac[i-1]*i)%mod; Ni[i] = niYuan(fac[i],mod); }}LL C(LL a,LL b){ return ((fac[a]*Ni[b])%mod*Ni[a-b]% mod)%mod;}int main(){ LL x,y,ans,a,b,c,pian; Init(); while(~scanf("%lld %lld",&y,&x)){ ans = 0; if(y%2 == 0){ if(x>=y/2+1) pian = (x-(y/2+1))*2+1; else pian = (y/2-x)*2+1; } else{ pian = abs((y+1)/2-x)*2; } a = pian; b = 0; while(a+b<=y-1){ c = (y-1-a-b)/2; ans = ans+(C(a+b+c,a)*C(b+c,b))%mod; ans = ans%mod; a++; b++; } printf("%lld\n",ans); } return 0;}
- Hex
- HEX
- hex
- Hex
- Hex
- HEX
- HEX文件格式
- hex格式
- Hex Editors
- HEX文件格式
- HEX文件格式
- poj_3765_Xiang Hex
- HEX 文件
- intel hex
- HEX文件格式
- Hex Fiend
- HEX文件格式
- Hex Editor
- HTML的基本结构语法 表格, 框架, 表单
- Codeforces 3D Least Cost Bracket Sequence
- 关于添加WINDOWS静态路由的方法
- 2017携程java后台开发工程师暑期实习生招聘面试经验分享
- Discuz!论坛教程之手机触屏版上传图片质量加强
- HEX
- 为什么CENTOS 7.0开始选择XFS作为默认的文件系统?XFS相比ext有什么优点?
- linux 添加路由
- dojo中的dojo/dom-construct
- apache Tomcat 配置账户管理项目
- C++抽象编程——回溯算法(3)——解决迷宫问题
- Windows右键新建md文件
- 运算符
- Unity加载AssetBundle后shader丢失问题