#include <stdio.h>
int dt[102][10002], w[102], v[102], n, W;
int max(int a, int b) {return a>b ? a:b;} //front
#include <cstring>
int f(int i, int r)
{
if(i>n) return 0;
if(dt[i][r]!=-1) return dt[i][r];
if(w[i]<=r) dt[i][r]=max(f(i+1, r), f(i+1, r-w[i])+v[i]);
else dt[i][r]=f(i+1, r);
return dt[i][r];
}
int main() {
memset(dt,-1,sizeof(dt));
scanf("%d %d", &n, &W);
for(int i=1; i<=n; i++)
scanf("%d%d", &w[i], &v[i]);
printf("%d", f(1,W));
return 0;
} //rear
To embed this project on your website, copy the following code and paste it into your website's HTML: