Guest User

Pay The Price

a guest
Jun 1st, 2015
2,548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define f(i,a,b) for(int i = (a); i <= (b); i++)
  3. #define SZ(x) ((int)x.size())
  4.  
  5. typedef long long ll;
  6. using namespace std;
  7.  
  8. ll DP[305][305], T[305][305];
  9.  
  10. vector<int> parse(string &s)
  11. {
  12.     s += ' ';
  13.     int n = 0;
  14.     vector<int> ret;
  15.     for(char c : s)
  16.         if(c == ' ') ret.push_back(n), n = 0;
  17.         else n = 10*n + c - '0';
  18.     return ret;
  19. }
  20.  
  21. ll query(int n, int l, int r)
  22. {
  23.     if(n == 0) return l == 0 ? 1 : 0;
  24.     l = max(l,1), r = min(r,300);
  25.     return DP[n][r] - DP[n][l-1];
  26. }
  27.  
  28. int main()
  29. {
  30.     DP[0][0] = 1;
  31.     f(c,1,300) f(i,c,300) f(j,1,300) DP[i][j] += DP[i-c][j-1];
  32.     f(i,1,300) f(j,1,300) DP[i][j] += DP[i][j-1];
  33.  
  34.     while(true)
  35.     {
  36.         string line;
  37.         getline(cin, line);
  38.         if(SZ(line) < 1) return 0;
  39.         vector<int> v = parse(line);
  40.         if(SZ(v) == 1) cout << query(v[0], 0, 300) << "\n";
  41.         if(SZ(v) == 2) cout << query(v[0], 0, v[1]) << "\n";
  42.         if(SZ(v) == 3) cout << query(v[0], v[1], v[2]) << "\n";
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment