[关闭]
@ZCDHJ 2018-10-02T16:11:35.000000Z 字数 665 阅读 460

NOIp2011 计算系数

组合数学


Luogu

通过二项式定理可知答案为

那么直接计算就行了。

  1. #include <iostream>
  2. #include <cstdio>
  3. typedef long long LL;
  4. #define int LL
  5. const int MOD = 10007;
  6. int a, b, k, n, m;
  7. inline int read() {
  8. register int x = 0;
  9. register char ch = getchar();
  10. while(!isdigit(ch)) ch = getchar();
  11. while(isdigit(ch)) {
  12. x = x * 10 + ch - '0';
  13. ch = getchar();
  14. }
  15. return x;
  16. }
  17. inline int fPow(int x, int y) {
  18. int res = 1, base = x;
  19. while(y) {
  20. if(y & 1) res = res * base % MOD;
  21. base = base * base % MOD;
  22. y >>= 1;
  23. }
  24. return res;
  25. }
  26. inline int C(int x, int y) {
  27. int xx = 1, yy = 1;
  28. for(int i = y + 1; i <= x; ++i) xx = xx * i % MOD;
  29. for(int i = 1; i <= x - y; ++i) yy = yy * i % MOD;
  30. return xx * fPow(yy, MOD - 2) % MOD;
  31. }
  32. signed main() {
  33. a = read();
  34. b = read();
  35. k = read();
  36. n = read();
  37. m = read();
  38. printf("%lld\n", C(k, n) * fPow(a, n) * fPow(b, m) % MOD);
  39. return 0;
  40. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注