fork download
  1. #include <bits/stdc++.h>
  2. #define endl '\n'
  3. #define ll long long
  4. #define task "COREWARD"
  5. using namespace std;
  6. const int N = 1e3, mod = 123456789;
  7.  
  8. int m, n;
  9. ll dp[N + 5][N + 5];
  10.  
  11. void add(ll &x, const ll &y)
  12. {
  13. (x += y) %= mod;
  14. }
  15.  
  16. int main()
  17. {
  18. ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  19. if(fopen(task".INP", "r"))
  20. {
  21. freopen(task".INP", "r", stdin);
  22. freopen(task".OUT", "w", stdout);
  23. }
  24.  
  25. cin >> m >> n;
  26.  
  27. dp[0][0] = 1;
  28. for(int i = 1; i <= n; ++i)
  29. for(int j = 0; j <= m; ++j)
  30. {
  31. add(dp[i][j], dp[i - 1][j]);
  32. if(j >= i)
  33. add(dp[i][j], dp[i][j - i]);
  34. }
  35.  
  36. cout << dp[n][m] << endl;
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0.01s 5304KB
stdin
3 2
stdout
2