SoL:01背包。。。
#include#include #include #include using namespace std; const int maxm = 1000 + 10; const int maxn = 100 + 10; int dp[maxm]; int value[maxn];//每袋的价格 int weight[maxn];//每袋的重量 int nValue,nKind; //0-1背包,代价为cost,获得的价值为weight void ZeroOnePack(int cost,int weight) { for(int i=nValue;i> =cost;i--) dp[i]=max(dp[i],dp[i-cost]+weight); } int main() { while(~scanf("%d%d",&nValue,&nKind)) { for(int i=0;i