-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathholstein.cpp
executable file
·70 lines (66 loc) · 1.62 KB
/
holstein.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
ID: paulius10
PROG: holstein
LANG: C++
*/
#include <fstream>
#include <queue>
#include <vector>
using namespace std;
struct state {
int startingIndex;
vector<int> remainingVitamins;
vector<int> usedFeeds;
};
int main() {
ifstream fin("holstein.in");
int V;
fin >> V;
int vitamins[V];
for (int i = 0; i < V; i++) fin >> vitamins[i];
int G;
fin >> G;
int feeds[G][V];
for (int i = 0; i < G; i++) {
for (int j = 0; j < V; j++) fin >> feeds[i][j];
}
fin.close();
state first;
first.startingIndex = 0;
for (int i = 0; i < V; i++) first.remainingVitamins.push_back(vitamins[i]);
queue<state> q;
q.push(first);
while (!q.empty()) {
state current = q.front();
q.pop();
bool ok = true;
for (int i = 0; i < V; i++) {
if (current.remainingVitamins[i] > 0) {
ok = false;
break;
}
}
if (ok) {
ofstream fout("holstein.out");
fout << current.usedFeeds.size() << " " << current.usedFeeds[0];
for (int i = 1; i < current.usedFeeds.size(); i++)
fout << " " << current.usedFeeds[i];
fout << endl;
fout.close();
return 0;
}
for (int i = current.startingIndex; i < G; i++) {
state newState;
newState.startingIndex = i + 1;
for (int j = 0; j < V; j++) {
newState.remainingVitamins.push_back(current.remainingVitamins[j] -
feeds[i][j]);
}
for (int j = 0; j < current.usedFeeds.size(); j++)
newState.usedFeeds.push_back(current.usedFeeds[j]);
newState.usedFeeds.push_back(i + 1);
q.push(newState);
}
}
return 0;
}