USACO原题,比较恶心……看得题解
表示DFS只有三十分,就不用尝试DFS了,去看洛谷题解吧
题号:1468
https://www.luogu.org/wiki/show?name=%E9%A2%98%E8%A7%A3+P1468
作者: ☜闪耀星空☞ 更新时间: 2017-08-10 10:11
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 | #include<cstdlib> #include<cstring> #include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; int n, c, a, t; bool light[10], dark[10],flag; int map[10][10] = { { 0, 1, 1, 1, 1, 1, 1 }, //0 { 0, 0, 0, 0, 0, 0, 0 }, //1 { 0, 0, 1, 0, 1, 0, 1 }, //2 { 0, 1, 0, 1, 0, 1, 0 }, //3 { 0, 0, 1, 1, 0, 1, 1 }, //4 { 0, 1, 0, 0, 1, 0, 0 }, //1,4 { 0, 1, 1, 0, 0, 0, 1 }, //2,4 { 0, 0, 0, 1, 1, 1, 0 }, //3,4 }; void print(int x){ for (int i = 1; i <= 6; i++){ if (light[i] && !map[x][i] || dark[i] && map[x][i])return; } flag = true; for (int i = 0; i < n; i++)cout << map[x][i % 6 + 1]; cout << endl; } int main(){ cin >> n >> c; while (cin >> t, t != -1)light[(t - 1) % 6 + 1] = true; while (cin >> t, t != -1)dark[(t - 1) % 6 + 1] = true; c = min(3, c); switch (c){ case 0:print(0); break; case 1:print(1); print(2); print(4); print(3); break; case 2:print(1); print(7); print(2); print(4); print(3); print(6); print(0); break; case 3:print(1); print(7); print(2); print(4); print(5); print(3); print(6); print(0); break; } if (!flag)cout << "IMPOSSIBLE" << endl; } |