#include<iostream>
using namespace std;
int max(int a,int b)
{int c;
if(a>b)
c=a;
else
c=b;
return c;
}
int main()
{ int f[20]={0};
int a[]={2,2,4,5,7};//5种东西的重量 只能背20的重量
int b[]={3,4,6,7,10 };//5种东西的价值
for(int i=0;i<5;i++)
for(int j=2;j<=20;j++)
{f[j]=max(f[j],f[j-a[i]]+b[i]);
}
cout<<f[20]<<endl;
system("pause");
}
using namespace std;
int max(int a,int b)
{int c;
if(a>b)
c=a;
else
c=b;
return c;
}
int main()
{ int f[20]={0};
int a[]={2,2,4,5,7};//5种东西的重量 只能背20的重量
int b[]={3,4,6,7,10 };//5种东西的价值
for(int i=0;i<5;i++)
for(int j=2;j<=20;j++)
{f[j]=max(f[j],f[j-a[i]]+b[i]);
}
cout<<f[20]<<endl;
system("pause");
}