fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. string pl(string a, string b){
  6. int x = a.size(), y = b.size();
  7. int r = 0;
  8. string ans;
  9. for(int i = 0; i < max(x, y); i++){
  10. if(a.size() == b.size()) break;
  11. if(a.size() < b.size()) a = '0' + a;
  12. else b = '0' + b;
  13. }
  14. x = a.size(); y = b.size();
  15. ans = a;
  16. for(int i = x - 1; i >= 0; i--){
  17. int c = ans[i] + b[i] - 2 * (int)'0' + r;
  18. r = c/10;
  19. c %= 10;
  20. ans[i] = char('0' + c);
  21. }
  22. if(r > 0) ans = char('0' + r) + ans;
  23. return ans;
  24. }
  25. int main()
  26. {
  27. ios_base::sync_with_stdio(false);
  28. cin.tie(0); cout.tie(0);
  29. ll n, d, k;
  30. cin >> n >> d >> k;
  31. n -= (d * k);
  32. if(n < 0) cout << 0;
  33. else{
  34. string c[1003][503];
  35. for(int i = 0; i <= 1000; i++){
  36. for(int j = 0; j <= 500; j++){
  37. if(i < j) c[i][j] = "0";
  38. else if(j == 0 || j == i) c[i][j] = "1";
  39. else c[i][j] = pl(c[i - 1][j], c[i - 1][j - 1]);
  40. }
  41. }
  42. cout << c[n + d - 1][d - 1];
  43. }
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0.27s 76064KB
stdin
500 500 0
stdout
135144120472718284757807346812987637748076004223274143503696437553312714352761096949306241962251185082681303042510773052401104875025339958774947109849759237711832742131875866678081232039868943672182287080559748802285522492878143940257300497109713376183457928301568431301242214054648452931899910608160