fork(2) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 1e3 + 5;
  6. const int MAX = 1e6 + 5;
  7. const long long M = 1e9 + 7;
  8.  
  9. int tc;
  10. int n, k[N];
  11. long long pre[N];
  12. long long fac[MAX], inv[MAX];
  13.  
  14. long long modpow(long long x, long long y, long long p) {
  15. long long ret = 1;
  16. while (y > 0) {
  17. if (y % 2 == 1) {
  18. ret = (ret * x) % M;
  19. }
  20. y /= 2;
  21. x = (x * x) % M;
  22. }
  23. return ret;
  24. }
  25.  
  26. long long C(long long a, long long b) {
  27. if (a < b) return 0;
  28. long long ret = (fac[a] * inv[b]) % M;
  29. ret = (ret * inv[a - b]) % M;
  30. return ret;
  31. }
  32.  
  33. int main() {
  34. ios_base::sync_with_stdio(0);
  35. cin.tie(0);
  36. cout.tie(0);
  37.  
  38. fac[0] = inv[0] = 1;
  39. for (int i = 1; i < MAX; i++) {
  40. fac[i] = (i * fac[i - 1]) % M;
  41. inv[i] = modpow(fac[i], M - 2, M);
  42. }
  43. cin >> tc;
  44. for (int tt = 1; tt <= tc; tt++) {
  45. cin >> n;
  46. for (int i = 1; i <= n; i++) {
  47. cin >> k[i];
  48. pre[i] = k[i] + pre[i - 1];
  49. }
  50. long long res = 1;
  51. for (int i = n; i >= 1; i--) {
  52. res = (res * C(pre[i] - 1, k[i] - 1)) % M;
  53. }
  54. cout << "Case " << tt << ": ";
  55. cout << res << '\n';
  56. }
  57.  
  58. return 0;
  59. }
Success #stdin #stdout 0.11s 19092KB
stdin
Standard input is empty
stdout
Standard output is empty