Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define f(i,a,b) for(int i = (a); i <= (b); i++)
- #define SZ(x) ((int)x.size())
- typedef long long ll;
- using namespace std;
- ll DP[305][305], T[305][305];
- vector<int> parse(string &s)
- {
- s += ' ';
- int n = 0;
- vector<int> ret;
- for(char c : s)
- if(c == ' ') ret.push_back(n), n = 0;
- else n = 10*n + c - '0';
- return ret;
- }
- ll query(int n, int l, int r)
- {
- if(n == 0) return l == 0 ? 1 : 0;
- l = max(l,1), r = min(r,300);
- return DP[n][r] - DP[n][l-1];
- }
- int main()
- {
- DP[0][0] = 1;
- f(c,1,300) f(i,c,300) f(j,1,300) DP[i][j] += DP[i-c][j-1];
- f(i,1,300) f(j,1,300) DP[i][j] += DP[i][j-1];
- while(true)
- {
- string line;
- getline(cin, line);
- if(SZ(line) < 1) return 0;
- vector<int> v = parse(line);
- if(SZ(v) == 1) cout << query(v[0], 0, 300) << "\n";
- if(SZ(v) == 2) cout << query(v[0], 0, v[1]) << "\n";
- if(SZ(v) == 3) cout << query(v[0], v[1], v[2]) << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment