-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path10130.cpp
More file actions
47 lines (44 loc) · 719 Bytes
/
10130.cpp
File metadata and controls
47 lines (44 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<stdio.h>
#define max(a,b) (a>b ?a:b)
#define si 1010
long cost[si],wei[si],n,mx,dp[si][40];
long rec_re(long i,long w)
{
long profit1,profit2;
if(i>n)
return 0;
if(dp[i][w]!=-1)
return dp[i][w];
if(w+wei[i]<=mx)
profit1=cost[i]+rec_re(i+1,w+wei[i]);
else
profit1=0;
profit2=rec_re(i+1,w);
dp[i][w]=max(profit1,profit2);
return dp[i][w];
}
int main()
{
long i,j,k,t,sum,g;
scanf("%ld",&t);
while(t--)
{
scanf("%ld",&n);
for(i=1;i<=n;i++)
scanf("%ld%ld",&cost[i],&wei[i]);
scanf("%ld",&g);
sum=0;
for(i=1;i<=g;i++)
{
scanf("%ld",&mx);
for(j=1;j<=n;j++)
{
for(k=0;k<=mx;k++)
dp[j][k]=-1;
}
sum+=rec_re(1,0);
}
printf("%ld\n",sum);
}
return 0;
}