Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- typedef long long ll;
- int n,W;
- int x[100][2];
- ll dp[101][100001];
- const ll infinity=1e13;
- ll rec(int at,int w){
- if(w==0){
- return 0;
- }
- if(at>=n){
- return 0;
- }
- if(dp[at][w] != -1) {
- return dp[at][w];
- }
- ll rez=-infinity;
- rez=max(rez,rec(at+1,w));
- if(w>=x[at][0]){
- rez=max(rez,rec(at+1,w-x[at][0])+x[at][1]);
- }
- dp[at][w] = rez;
- return rez;
- }
- int main()
- {
- memset(dp, -1, sizeof dp);
- cin>>n>>W;
- for(int i = 0;i<n;i++){
- cin>>x[i][0];
- cin>>x[i][1];
- }
- cout<<rec(0, W);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement