如果确定了选哪几个,顺序肯定是Li大的先选,所以可以按Li排序,再像0-1背包一样依次添加
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int dp[1001];
struct op
{
int w,v;
}p[1001];
int cmp(const void *a,const void *b)
{
struct op *c,*d;
c=(struct op *)a;
d=(struct op *)b;
return d->v-c->v;
}
int main()
{
int i,j,n,k,max;
while(scanf("%d%d",&n,&k)!=-1)
{
memset(dp,0,sizeof(dp));
for(i=0;i<n;i++)
scanf("......
阅读全文