-
Notifications
You must be signed in to change notification settings - Fork 12
/
WACHOVIA.cpp
50 lines (39 loc) · 1.08 KB
/
WACHOVIA.cpp
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
48
49
50
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int w,n;
cin>>w>>n;
int dp[n+1][w+1];
int wt[n],pr[n];
for(int i=0;i<=n;i++){
for(int j=0;j<=w;j++)
{
dp[i][j]=0;
}
}
for(int i=0;i<n;i++)
{
cin>>wt[i]>>pr[i];
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=w;j++)
{
if(wt[i-1]<=j)
{
dp[i][j] = max(dp[i-1][j],dp[i-1][j-wt[i-1]]+pr[i-1]);
}
else
{
dp[i][j]=dp[i-1][j];
}
}
}
cout<<"Hey stupid robber, you can get "<<dp[n][w]<<"."<<endl;
}
}