1
2 #include<iostream>
3 #include<cstdio>
4 #include<memory.h>
5 using namespace std;
6 #define max(a,b) a>b?a:b
7 #define MAX 50005
8 #define M 2005
9
10 struct goods{
11 int c; //重量
12 int w; //价值
13 }a[M];
14
15 int dp[MAX];
16
17 int main()
18 {
19 // freopen("in.txt","r",stdin);
20 int t,i,j,N,m;
21 scanf("%d",&t);
22 while(t--)
23 {
24 scanf("%d%d",&m,&N);
25 for(i=1; i<=N; ++i)
26 dp[i] = -500000000;
27 dp[0] = 0;
28 for(i = 0; i !=m; ++i)
29 {
30 cin>>a[i].c>>a[i].w;
31 for(int k = 0; k < i; ++k)
32 if(a[k].c <= a[i].c && a[k].w >= a[i].w)
33 break;
34 if(a[i].c > N) continue;
35 for(j = a[i].c; j <= N; ++j)
36 dp[j] = max(dp[j], dp[j - a[i].c] + a[i].w);
37 }
38 if(dp[N] > 0)
39 printf("%d\n",dp[N]);
40 else
41 printf("NO\n");
42 }
43 return 0;
44 }
2 #include<iostream>
3 #include<cstdio>
4 #include<memory.h>
5 using namespace std;
6 #define max(a,b) a>b?a:b
7 #define MAX 50005
8 #define M 2005
9
10 struct goods{
11 int c; //重量
12 int w; //价值
13 }a[M];
14
15 int dp[MAX];
16
17 int main()
18 {
19 // freopen("in.txt","r",stdin);
20 int t,i,j,N,m;
21 scanf("%d",&t);
22 while(t--)
23 {
24 scanf("%d%d",&m,&N);
25 for(i=1; i<=N; ++i)
26 dp[i] = -500000000;
27 dp[0] = 0;
28 for(i = 0; i !=m; ++i)
29 {
30 cin>>a[i].c>>a[i].w;
31 for(int k = 0; k < i; ++k)
32 if(a[k].c <= a[i].c && a[k].w >= a[i].w)
33 break;
34 if(a[i].c > N) continue;
35 for(j = a[i].c; j <= N; ++j)
36 dp[j] = max(dp[j], dp[j - a[i].c] + a[i].w);
37 }
38 if(dp[N] > 0)
39 printf("%d\n",dp[N]);
40 else
41 printf("NO\n");
42 }
43 return 0;
44 }