-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path54-2.cpp
More file actions
46 lines (45 loc) · 994 Bytes
/
54-2.cpp
File metadata and controls
46 lines (45 loc) · 994 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
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
int main()
{
int m,tw,n,i,j,sz,ve;
vector <int> store;
vector <int> w;
string buffer;
cin>>m;
while(m--)
{
cin>>tw;
cin>>n;
for(i=0;i<n;i++)
{
cin>>sz>>ve>>buffer;
for(j=0;j<tw/sz;j++)
{
store.push_back(ve);
w.push_back(sz);
}
}
int c[w.size()+1][tw+1];
memset(c,0,sizeof(c));
for(i=0;i<w.size();i++)
{
for(j=0;j<=tw;j++)
{
if(j-w[i]<0)
c[i+1][j]=c[i][j];
else
{
c[i+1][j]=max(c[i][j],c[i][j-w[i]]+store[i]);
}
}
}
cout<<"Total: "<<c[i][tw]<<endl;
store.clear();
w.clear();
}
return 0;
}