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 71 72 73 74 75 76 77
| #include<iostream> #include<cstdlib> #include<ctime> #include<cstring> #include<vector>
enum turn{LEFT,RIGHT}; int weights[2][10] = { {1,2,3,4,5,6,7,8,9,10} ,{0,0,0,0,0,0,0,0,0,0}}; int count = 0; std::vector<int> temp;
void process(int lw,int rw,int w, int m,std::vector<int> temp,turn t) { if (count == -1) return; if (m == count) { count = -1; for (int i : temp) std::cout << i << " "; } if (t == turn::LEFT) { if (lw + w <= rw) return; else { lw += w; m++; temp.push_back(w); for (int i = 0; i < 10; i++) { if (weights[1][i] == 0 || w == i+1) continue; process(lw, rw, weights[0][i], m, temp, turn::RIGHT); } } }
if (t == turn::RIGHT) { if (rw + w <= lw) return; else { rw += w; m++; temp.push_back(w); for (int i = 0; i < 10; i++) { if (weights[1][i] == 0 || w == i+1) continue; process(lw, rw, weights[0][i], m, temp, turn::LEFT); } } } }
void put(int count) { for (int i = 0; i < 10; i++) { if (weights[1][i] == 0) continue; process(0, 0, weights[0][i], 0, temp, turn::LEFT); } } int main() { weights[1][7] = 1; weights[1][9] = 1; weights[1][1] = 1; count = 7; put(count); }
|