fork download
  1. #include <algorithm>
  2. #include <bitset>
  3. #include <climits>
  4. #include <cmath>
  5. #include <cstdio>
  6. #include <cstring>
  7. #include <ctime>
  8. #include <deque>
  9. #include <functional>
  10. #include <iomanip>
  11. #include <iostream>
  12. #include <list>
  13. #include <map>
  14. #include <queue>
  15. #include <set>
  16. #include <sstream>
  17. #include <stack>
  18. #include <string>
  19. #include <vector>
  20.  
  21. using namespace std;
  22.  
  23. #define FOR(i, N) for(int i = 0; i < N; i++)
  24. #define FOR1e(i, N) for(int i = 1; i <= N; i++)
  25. #define REP(i, M, N) for(int i = M; i < N; i++)
  26. #define REPe(i, M, N) for(int i = M; i <= N; i++)
  27. #define sc(N) scanf("%d", &N)
  28. #define scsc(M, N) scanf("%d %d", &M, &N)
  29. #define gt(s) getline(cin, s)
  30. #define all(s) s.begin(), s.end()
  31. #define ll long long
  32. #define vi vector <int>
  33. #define pii pair <int, int>
  34. #define ss stringstream
  35. #define pq priority_queue
  36. #define mp make_pair
  37. #define pb push_back
  38. #define ms(a, v) memset(a, v, sizeof a)
  39.  
  40. const int MAX = 1e5 + 1;
  41. const int MOD = 1988;
  42.  
  43. int dr[] = {0, -1, 0, 1};
  44. int dc[] = {1, 0, -1, 0};
  45.  
  46. inline int Pow(int b, int p) {if(!p) return 1; int sq = Pow(b, p >> 1); sq *= sq; if(p&1) sq *= b; return sq;}
  47. inline int gcd(int a, int b) {if(!a) return b; return gcd(b % a, a);}
  48.  
  49. int n, k;
  50. ll dp[5005][5005];
  51.  
  52. ll solve(int rem, int cur, int last){
  53. if(cur == k)
  54. return rem == 0;
  55. if(!rem)
  56. return 0;
  57. ll &ret = dp[rem][cur];
  58. if(ret != -1)
  59. return ret;
  60. ret = 0;
  61. REPe(i, last, rem)
  62. ret = (ret % MOD + solve(rem - i, cur + 1, i) % MOD) % MOD;
  63. return ret;
  64. }
  65.  
  66. int main(){
  67. #ifndef ONLINE_JUDGE
  68. freopen("in.txt", "r", stdin);
  69. #endif
  70. while(scsc(n, k) != EOF){
  71. if(!n && !k)
  72. break;
  73. ms(dp, -1);
  74. printf("%lld\n", solve(n, 0, 1));
  75. }
  76. return 0;
  77. }
  78.  
Success #stdin #stdout 0s 198976KB
stdin
Standard input is empty
stdout
Standard output is empty