山东 acm D HEX 数学 求组合数
来源:互联网 发布:有声单词软件下载 编辑:程序博客网 时间:2024/06/06 02:21
HEX
Time Limit: 4000MS Memory Limit: 131072KB
Submit Statistic
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 1
3 2
100000 100000
Example Output
1
3
1
Hint
Author
利用 (1,1)+x*(1,0)+y*(2,1)+z*(1,1)=(a,b).
求得 x+2*y+z=a-1;y+z=b-1; 得 x+y=a-b; y+z=b-1 y<=min(a-b,b-1)
枚举y,解出,x,z,然后解出 c(x+y+z,x)*C(y+z,y)*C(z,z) ,表明走x个左方向 y个下方向和z个右方向有多少种方案, 用 res加上。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;ll fact[101010],inv[101010];const int mod=1e9+7;const int maxn=1e5+7;ll quickM(ll a, ll b){ ll base = a%mod, ans = 1; while(b){ if(b&1) ans = ans*base%mod; base = base*base%mod; b >>= 1; } return ans;}void init(){ fact[0] = 1; for(int i = 1; i <= maxn; ++i) fact[i] = fact[i-1]*i%mod; inv[maxn]=quickM(fact[maxn],mod-2); for(int i=maxn-1;i>=0;i--) { inv[i]=inv[i+1]*(i+1); inv[i]%=mod; }}ll C(int n, int m){ return ((fact[n]*inv[m])%mod*(inv[n-m]))%mod;}int main(){ int a,b; init(); while(cin>>a>>b) { long long res=0; int n=min(a-b,b-1); for(ll y=0;y<=min(a-b,b-1);y++) { ll z=b-1-y; ll x=a-b-y; res+=(C(z+y+x,x)*C(z+y,y))%mod; res%=mod; } printf("%lld\n",res ); }}
- 山东 acm D HEX 数学 求组合数
- SDUT 3896 HEX 山东第八届ACM大赛D题(组合数学)
- 2017山东省第八届ACM省赛 D. HEX(组合数学)
- [2011山东ACM省赛] Binomial Coeffcients(求组合数)
- 山东省第八届acm省赛D题HEX(组合数学)
- 2011年山东ACM第二届省赛 Binomial Coeffcients(求组合数)
- 求组合数(数学)
- acm 求组合数方法
- ACM数论-求组合数
- HEX--之组合数学
- 第八届山东acm省赛 C题 fireworks (组合数)
- HEX(组合数+线性代数)
- [2010山东ACM省赛] Greatest Number(数的组合+二分搜索)
- fireworks----乘法逆元求组合数(2017山东ACM-ICPC省赛)
- ACM 93. [NOIP2001] 数的划分(dp+组合数学)
- 组合数学:D - Cellular Automaton 求矩阵相乘
- HEX----组合数+逆元+思维 山东省第八届省赛D题
- hatuoj 1300 HEX----组合数+逆元+思维 山东省第八届省赛D题
- Android 源码解析之AsyncTask
- ubuntu系统安装Go和liteide及环境配置
- 请大神帮小白屡屡思路
- 过滤器
- org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper: too_many_clauses: maxClauseCount
- 山东 acm D HEX 数学 求组合数
- git如何撤销所有本地修改
- 再谈布局之 UIStackView
- Android开发中获取当前网络类型的方法
- Android 性能优化——避免过度绘制
- Android6.0运行时权限管理
- React Native环境配置之Windows版本搭建
- [leetcode:python]69.Sqrt(x)
- google 浏览器使用的一些小技巧