-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1021.cpp
More file actions
60 lines (56 loc) · 1018 Bytes
/
Copy path1021.cpp
File metadata and controls
60 lines (56 loc) · 1018 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
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include<vector>
#include <map>
#include<algorithm>
#include <math.h>
using namespace std;
int m, n, k;
//int* r = new int(n + 1);//r[i]表示长度为i米的钢条的最大收益
int r[10000];
int main()
{
cin >> m;
while (m--) {
cin >> n;//钢条长度
cin >> k;//价格表有几组
vector<int>Lvec(1, 0);//长度
vector<int>Pvec(1, 0);//价格
map<int, int>mp;
for (int i = 1; i <= k; i++) {//输入
int p1, p2;
cin >> p1;
cin >> p2;
mp.insert(pair<int, int>(p1, p2));
}
map<int, int>::iterator it;
for (it = mp.begin(); it != mp.end(); it++) {
Lvec.push_back(it->first);
Pvec.push_back(it->second);
}
if (n < Lvec[1])
{
cout << 0 << endl;
continue;
}
for (int i = 0; i < Lvec[1]; i++)
{
r[i] = 0;
}
int q = 0;
for (int i = 0; i <= n; i++)//钢条最大长度递增
{
for (int j = 1; j <= k; j++)
{
if (i >= Lvec[j])
{
q = max(q, Pvec[j] + r[i - Lvec[j]]);
}
else
break;
}
r[i] = q;
}
cout << q << endl;
}
return 0;
}