-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
68 lines (65 loc) · 1.11 KB
/
D.cpp
File metadata and controls
68 lines (65 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<bits/stdc++.h>
using namespace std;
void subset(int a[],int n,int i,string osf)
{
if(i==n)
{
cout<<osf<<endl;
return ;
}
subset(a,5,i+1,osf+to_string(a[i])+" ");
subset(a,5,i+1,osf);
}
int c=0;
void lex(string s,int n)
{
if(c>=n+1)
return ;
stringstream ss(s);
int k;
ss>>k;
if(k<=n)
{
c++;
cout<<s<<endl;
}
if(s>to_string(n))
return ;
for(int i=1;i<10;i++)
{
lex(s+to_string(i),n);
}
}
long long dp[105][100005];
long long knapsack(int w[],int v[],int c,int n)
{
if(c==0 || n==0)
{
return 0;
}
if(dp[n][c]!=-1)
return dp[n][c];
if(w[n-1]<=c)
{
return dp[n][c]=max(v[n-1]+knapsack(w,v,c-w[n-1],n-1),knapsack(w,v,c,n-1));
}
else
{
return dp[n][c]=knapsack(w,v,c,n-1);
}
}
int main()
{
//
// int w[5]={2,4,6,8,10};
// int v[5]={1,3,6,9,9};
// int c=15;
int n,c;
cin>>n>>c;
int w[n],v[n];
for(int i=0;i<n;i++)
cin>>w[i]>>v[i];
memset(dp,-1,sizeof(dp));
cout<<knapsack(w,v,c,n);
return 0;
}