mickypinata

PROG-T1172: Crystal

Aug 8th, 2021 (edited)
1,120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1000;
  5. const int MD = 10001;
  6.  
  7. int dp[N + 1], qs[N + 1];
  8.  
  9. int main(){
  10.  
  11.     int x;
  12.     scanf("%d", &x);
  13.     if(x == 1){
  14.         cout << '1';
  15.         return 0;
  16.     }
  17.     dp[2] = 1;
  18.     qs[2] = 1;
  19.     qs[3] = 1;
  20.     for(int i = 3; i <= x; ++i){
  21.         for(int j = 2; j <= i; ++j){
  22.             dp[j] = (MD + qs[i] - qs[j - 2]) % MD;
  23.         }
  24.         for(int j = 2; j <= i + 1; ++j){
  25.             qs[j] = (qs[j - 1] + dp[j]) % MD;
  26.         }
  27.     }
  28.     int ans = 0;
  29.     for(int i = 2; i <= x; ++i){
  30.         ans = (ans + i * dp[i]) % MD;
  31.     }
  32.     cout << ans;
  33.  
  34.     return 0;
  35. }
  36.  
Add Comment
Please, Sign In to add comment