1 #include<stdio.h>
 2 #include<algorithm>
 3 #include<string.h>
 4 using namespace std;
 5 int bag[1001];
 6 struct Case{
 7     int c,w;
 8 }apple[1010];
 9 /*int cmp(Case a,Case b){
10     return (1.0*a.w/a.c)>(1.0*b.w/b.c);
11 }*/
12 int main(){
13     int n,v;
14     while(scanf("%d%d",&n,&v),n||v){memset(bag,0,sizeof(bag));
15         for(int i=0;i<n;++i)scanf("%d%d",&apple[i].c,&apple[i].w);
16         /*sort(apple,apple+n,cmp);*/
17         for(int i=0;i<n;++i){ //printf("%d ",apple[i].c);
18             for(int j=v;j>=apple[i].c;j--)if(bag[j-apple[i].c]+apple[i].w>bag[j])bag[j]=bag[j-apple[i].c]+apple[i].w;
19         }
20         printf("%d\n",bag[v]);
21     }
22     return 0;
23 }

 

相关文章:

  • 2021-11-29
  • 2021-04-02
  • 2021-05-31
  • 2022-12-23
  • 2021-05-15
  • 2022-01-07
猜你喜欢
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2021-08-30
  • 2021-08-21
  • 2021-07-20
  • 2021-10-16
相关资源
相似解决方案