首页 > 代码库 > XDOJ_1158_组合
XDOJ_1158_组合
http://acm.xidian.edu.cn/problem.php?id=1158
答案为,并不是很懂。
直接套lucas都超时了,打表预处理一下。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define LL long long #define MOD (long long)(1e9+7) using namespace std; int x,y,k; LL fac[2000005]; LL PowerMod(LL a, LL b, LL c) { LL ans = 1; a = a % c; while(b) { if(b&1) ans = (ans*a)%c; b = b>>1; a = (a*a)%c; } return ans; } LL inv(LL x) { return PowerMod(x,MOD-2,MOD); } int main() { fac[1] = 1; for(int i = 2;i <= 2000000;i++) fac[i] = fac[i-1]*i%MOD; while(~scanf("%d%d%d",&x,&y,&k)) { if(y == k) printf("1\n"); else if(y < k) printf("0\n"); else printf("%lld\n",fac[x+y]*inv(fac[x+k])%MOD*inv(fac[y-k])%MOD); } return 0; }
XDOJ_1158_组合
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。