|
| 1 | +#include <iostream> |
| 2 | +#include <sstream> |
| 3 | +#include <vector> |
| 4 | +#include <algorithm> |
| 5 | +#include <set> |
| 6 | +#include <map> |
| 7 | +#include <queue> |
| 8 | +#include <cstring> |
| 9 | +#include <climits> |
| 10 | +#include <cstdio> |
| 11 | +using namespace std; |
| 12 | +typedef pair<int,int> pi; |
| 13 | +typedef vector<int> vi; |
| 14 | +typedef vector<vi> vvi; |
| 15 | +typedef vector<string> vs; |
| 16 | +typedef vector<vs> vvs; |
| 17 | + |
| 18 | +class GoldMine{ |
| 19 | + public: |
| 20 | + int value(string m, int k){ |
| 21 | + int cost = 0; |
| 22 | + vi v(7); |
| 23 | + sscanf(m.c_str(), "%d, %d, %d, %d, %d, %d, %d", &v[0], &v[1], &v[2], &v[3], &v[4], &v[5], &v[6]); |
| 24 | + for(int i = 0; i <= 6; i++){ |
| 25 | + if(k < i) cost += v[i]*k*60; |
| 26 | + else cost += v[i]*(50*i - 20*(k-i)); |
| 27 | + // cout<<v[i]<<", "; |
| 28 | + // cout<<cost<<" "; |
| 29 | + } |
| 30 | + // cost /= 100; |
| 31 | + // cout<<m<<" "<<k<<" = "<<cost<<endl; |
| 32 | + return cost; |
| 33 | + } |
| 34 | + vector <int> getAllocation(vector <string> mines, int miners) { |
| 35 | + int dp[55][500]; |
| 36 | + int q[55][500]; |
| 37 | + pi p[55][500]; |
| 38 | + int n = mines.size(); |
| 39 | + for(int k = 0; k <= miners; k++){ |
| 40 | + if(k <= 6) dp[0][k] = value(mines[0], k); |
| 41 | + else dp[0][k] = -1000000; |
| 42 | + p[0][k] = make_pair(-1, -1); |
| 43 | + q[0][k] = k; |
| 44 | + } |
| 45 | + |
| 46 | + for(int i = 1; i < n; i++) |
| 47 | + for(int s = 0; s <= miners; s++){ |
| 48 | + int maxv = -1000000, maxq = 10; |
| 49 | + pi maxp = make_pair(-1, -1); |
| 50 | + for(int k = 0; k <= 6; k++){ |
| 51 | + if(s < k) continue; |
| 52 | + int val = dp[i-1][s-k]+value(mines[i], k); |
| 53 | + if(maxv < val){ |
| 54 | + maxv = val; |
| 55 | + maxp = make_pair(i-1, s-k); |
| 56 | + maxq = k; |
| 57 | + } |
| 58 | + } |
| 59 | + dp[i][s] = maxv; |
| 60 | + p[i][s] = maxp; |
| 61 | + q[i][s] = maxq; |
| 62 | + // cout<<"dp["<<i<<"]["<<s<<"] = "<<maxv<<" p = <"<<maxp.first<<","<<maxp.second<<"> q = "<<maxq<<endl; |
| 63 | + } |
| 64 | + |
| 65 | + int i = n-1, s = miners; |
| 66 | + vi ret(n); |
| 67 | + while(i >= 0){ |
| 68 | + ret[i] = q[i][s]; |
| 69 | + pi t = p[i][s]; |
| 70 | + i = t.first; s = t.second; |
| 71 | + } |
| 72 | + if(n == 9){ |
| 73 | + int a[9] = {5, 5, 5, 5, 6, 6, 5, 5, 6}; |
| 74 | + vi av(a, a+9); |
| 75 | + int acost = 0; |
| 76 | + for(int i = 0; i < 9; i++) acost += value(mines[i], a[i]); |
| 77 | + cout<<"acost = "<<acost<<endl; |
| 78 | + int b[9] = {5, 6, 6, 5, 5, 6, 5, 5, 5}; |
| 79 | + vi bv(b, b+9); |
| 80 | + int bcost = 0; |
| 81 | + for(int i = 0; i < 9; i++) bcost += value(mines[i], b[i]); |
| 82 | + cout<<"bcost = "<<bcost<<endl; |
| 83 | + } |
| 84 | + |
| 85 | + cout<<"maxval = "<<dp[n-1][miners]<<endl; |
| 86 | + |
| 87 | + return ret; |
| 88 | + //return dp[n-1][miners]; |
| 89 | + } |
| 90 | + |
| 91 | +// BEGIN CUT HERE |
| 92 | + public: |
| 93 | + void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); } |
| 94 | + private: |
| 95 | + template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); } |
| 96 | + void verify_case(int Case, const vector <int> &Expected, const vector <int> &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: " << print_array(Expected) << endl; cerr << "\tReceived: " << print_array(Received) << endl; } } |
| 97 | + void test_case_0() { string Arr0[] = { "000, 030, 030, 040, 000, 000, 000", |
| 98 | + "020, 020, 020, 010, 010, 010, 010" }; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 4; int Arr2[] = { 2, 2 }; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); verify_case(0, Arg2, getAllocation(Arg0, Arg1)); } |
| 99 | + void test_case_1() { string Arr0[] = { "100, 000, 000, 000, 000, 000, 000", |
| 100 | + "100, 000, 000, 000, 000, 000, 000", |
| 101 | + "100, 000, 000, 000, 000, 000, 000", |
| 102 | + "100, 000, 000, 000, 000, 000, 000", |
| 103 | + "100, 000, 000, 000, 000, 000, 000" }; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 8; int Arr2[] = { 6, 2, 0, 0, 0 }; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); verify_case(1, Arg2, getAllocation(Arg0, Arg1)); } |
| 104 | + void test_case_2() { string Arr0[] = { "050, 000, 000, 000, 000, 050, 000", |
| 105 | + "050, 000, 000, 000, 000, 050, 000", |
| 106 | + "050, 000, 000, 000, 000, 050, 000", |
| 107 | + "050, 000, 000, 000, 000, 050, 000", |
| 108 | + "050, 000, 000, 000, 000, 050, 000", |
| 109 | + "050, 000, 000, 000, 000, 050, 000", |
| 110 | + "050, 000, 000, 000, 000, 050, 000", |
| 111 | + "050, 000, 000, 000, 000, 050, 000", |
| 112 | + "050, 000, 000, 000, 000, 050, 000", |
| 113 | + "050, 000, 000, 000, 000, 050, 000" }; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 30; int Arr2[] = { 4, 4, 4, 4, 4, 4, 4, 2, 0, 0 }; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); verify_case(2, Arg2, getAllocation(Arg0, Arg1)); } |
| 114 | + void test_case_3() { string Arr0[] = { "026, 012, 005, 013, 038, 002, 004", |
| 115 | + "026, 012, 005, 013, 038, 002, 004", |
| 116 | + "026, 012, 005, 013, 038, 002, 004", |
| 117 | + "026, 012, 005, 013, 038, 002, 004", |
| 118 | + "026, 012, 005, 013, 038, 002, 004", |
| 119 | + "026, 012, 005, 013, 038, 002, 004", |
| 120 | + "026, 012, 005, 013, 038, 002, 004", |
| 121 | + "026, 012, 005, 013, 038, 002, 004", |
| 122 | + "026, 012, 005, 013, 038, 002, 004", |
| 123 | + "026, 012, 005, 013, 038, 002, 004", |
| 124 | + "026, 012, 005, 013, 038, 002, 004", |
| 125 | + "026, 012, 005, 013, 038, 002, 004", |
| 126 | + "026, 012, 005, 013, 038, 002, 004", |
| 127 | + "026, 012, 005, 013, 038, 002, 004", |
| 128 | + "026, 012, 005, 013, 038, 002, 004", |
| 129 | + "026, 012, 005, 013, 038, 002, 004", |
| 130 | + "026, 012, 005, 013, 038, 002, 004", |
| 131 | + "026, 012, 005, 013, 038, 002, 004", |
| 132 | + "026, 012, 005, 013, 038, 002, 004", |
| 133 | + "026, 012, 005, 013, 038, 002, 004", |
| 134 | + "026, 012, 005, 013, 038, 002, 004", |
| 135 | + "026, 012, 005, 013, 038, 002, 004", |
| 136 | + "026, 012, 005, 013, 038, 002, 004", |
| 137 | + "026, 012, 005, 013, 038, 002, 004", |
| 138 | + "026, 012, 005, 013, 038, 002, 004", |
| 139 | + "026, 012, 005, 013, 038, 002, 004", |
| 140 | + "026, 012, 005, 013, 038, 002, 004", |
| 141 | + "026, 012, 005, 013, 038, 002, 004", |
| 142 | + "026, 012, 005, 013, 038, 002, 004", |
| 143 | + "026, 012, 005, 013, 038, 002, 004", |
| 144 | + "026, 012, 005, 013, 038, 002, 004", |
| 145 | + "026, 012, 005, 013, 038, 002, 004", |
| 146 | + "026, 012, 005, 013, 038, 002, 004", |
| 147 | + "026, 012, 005, 013, 038, 002, 004", |
| 148 | + "026, 012, 005, 013, 038, 002, 004", |
| 149 | + "026, 012, 005, 013, 038, 002, 004", |
| 150 | + "026, 012, 005, 013, 038, 002, 004", |
| 151 | + "026, 012, 005, 013, 038, 002, 004", |
| 152 | + "026, 012, 005, 013, 038, 002, 004", |
| 153 | + "026, 012, 005, 013, 038, 002, 004", |
| 154 | + "026, 012, 005, 013, 038, 002, 004", |
| 155 | + "026, 012, 005, 013, 038, 002, 004", |
| 156 | + "026, 012, 005, 013, 038, 002, 004", |
| 157 | + "026, 012, 005, 013, 038, 002, 004", |
| 158 | + "026, 012, 005, 013, 038, 002, 004", |
| 159 | + "026, 012, 005, 013, 038, 002, 004", |
| 160 | + "026, 012, 005, 013, 038, 002, 004", |
| 161 | + "026, 012, 005, 013, 038, 002, 004", |
| 162 | + "026, 012, 005, 013, 038, 002, 004", |
| 163 | + "026, 012, 005, 013, 038, 002, 004" }; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 56; int Arr2[] = { 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); verify_case(3, Arg2, getAllocation(Arg0, Arg1)); } |
| 164 | + void test_case_4() { string Arr0[] = { "100, 000, 000, 000, 000, 000, 000", |
| 165 | + "090, 010, 000, 000, 000, 000, 000", |
| 166 | + "080, 020, 000, 000, 000, 000, 000", |
| 167 | + "075, 025, 000, 000, 000, 000, 000", |
| 168 | + "050, 050, 000, 000, 000, 000, 000", |
| 169 | + "025, 075, 000, 000, 000, 000, 000", |
| 170 | + "020, 080, 000, 000, 000, 000, 000", |
| 171 | + "010, 090, 000, 000, 000, 000, 000", |
| 172 | + "000, 100, 000, 000, 000, 000, 000", |
| 173 | + "000, 090, 010, 000, 000, 000, 000", |
| 174 | + "000, 080, 020, 000, 000, 000, 000", |
| 175 | + "000, 075, 025, 000, 000, 000, 000", |
| 176 | + "000, 050, 050, 000, 000, 000, 000", |
| 177 | + "000, 025, 075, 000, 000, 000, 000", |
| 178 | + "000, 020, 080, 000, 000, 000, 000", |
| 179 | + "000, 010, 090, 000, 000, 000, 000", |
| 180 | + "000, 000, 100, 000, 000, 000, 000", |
| 181 | + "000, 000, 090, 010, 000, 000, 000", |
| 182 | + "000, 000, 080, 020, 000, 000, 000", |
| 183 | + "000, 000, 075, 025, 000, 000, 000", |
| 184 | + "000, 000, 050, 050, 000, 000, 000", |
| 185 | + "000, 000, 025, 075, 000, 000, 000", |
| 186 | + "000, 000, 020, 080, 000, 000, 000", |
| 187 | + "000, 000, 010, 090, 000, 000, 000", |
| 188 | + "000, 000, 000, 100, 000, 000, 000", |
| 189 | + "000, 000, 000, 100, 000, 000, 000", |
| 190 | + "000, 000, 000, 090, 010, 000, 000", |
| 191 | + "000, 000, 000, 080, 020, 000, 000", |
| 192 | + "000, 000, 000, 075, 025, 000, 000", |
| 193 | + "000, 000, 000, 050, 050, 000, 000", |
| 194 | + "000, 000, 000, 025, 075, 000, 000", |
| 195 | + "000, 000, 000, 020, 080, 000, 000", |
| 196 | + "000, 000, 000, 010, 090, 000, 000", |
| 197 | + "000, 000, 000, 000, 100, 000, 000", |
| 198 | + "000, 000, 000, 000, 090, 010, 000", |
| 199 | + "000, 000, 000, 000, 080, 020, 000", |
| 200 | + "000, 000, 000, 000, 075, 025, 000", |
| 201 | + "000, 000, 000, 000, 050, 050, 000", |
| 202 | + "000, 000, 000, 000, 025, 075, 000", |
| 203 | + "000, 000, 000, 000, 020, 080, 000", |
| 204 | + "000, 000, 000, 000, 010, 090, 000", |
| 205 | + "000, 000, 000, 000, 000, 100, 000", |
| 206 | + "000, 000, 000, 000, 000, 090, 010", |
| 207 | + "000, 000, 000, 000, 000, 080, 020", |
| 208 | + "000, 000, 000, 000, 000, 075, 025", |
| 209 | + "000, 000, 000, 000, 000, 050, 050", |
| 210 | + "000, 000, 000, 000, 000, 025, 075", |
| 211 | + "000, 000, 000, 000, 000, 020, 080", |
| 212 | + "000, 000, 000, 000, 000, 010, 090", |
| 213 | + "000, 000, 000, 000, 000, 000, 100" }; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 150; int Arr2[] = { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6 }; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); verify_case(4, Arg2, getAllocation(Arg0, Arg1)); } |
| 214 | + |
| 215 | +// END CUT HERE |
| 216 | + |
| 217 | +}; |
| 218 | + |
| 219 | +// BEGIN CUT HERE |
| 220 | +int main(){ |
| 221 | + |
| 222 | + GoldMine ___test; |
| 223 | + ___test.run_test(-1); |
| 224 | +} |
| 225 | +// END CUT HERE |
0 commit comments