forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path104.cpp
More file actions
54 lines (51 loc) · 995 Bytes
/
104.cpp
File metadata and controls
54 lines (51 loc) · 995 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
//Little shop of flowers
#include <iostream>
#include <string>
using namespace std;
#ifdef WIN32
#define for if(0); else for
#endif
int main() {
int a[100][100];
int b[100][100];
int f, v;
cin >> f >> v;
for (int i = 0; i < f; i ++) {
for (int j = 0; j < v; j ++) {
cin >> a[i][j];
b[i][j] = -500000;
}
}
for (int i = 0; i < v; i ++) b[f - 1][i] = a[f - 1][i];
for (int i = f - 2; i >= 0; i --) {
for (int j = 0; j < v; j ++) {
int temp = -500000;
for (int t = j + 1; t < v; t ++) {
if (b[i + 1][t] > temp) temp = b[i + 1][t];
}
b[i][j] = a[i][j] + temp;
}
}
int res = -500000, index;
for (int i = 0; i < v; i ++) {
if (b[0][i] > res) {
res = b[0][i];
index = i;
}
}
cout << res << endl;
cout << index + 1;
res -= a[0][index];
for (int i = 1; i < f; i ++) {
for (int j = index + 1; j < v; j ++) {
if (b[i][j] == res) {
cout << " " << j + 1;
res -= a[i][j];
index = j;
break;
}
}
}
cout << endl;
return 0;
}