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
| #include <stdio.h> #include <string> using namespace std; string DP[21][21][21][21][2]; void make_str(string s, int a, int b, int c, int d, int last){ DP[a][b][c][d][last]=s; switch(s[s.length()-1]){ case '0' : if(a<20&&DP[a+1][b][c][d][0].empty()) make_str(s + '0',a + 1, b, c, d,0); if(b<20&&DP[a][b+1][c][d][1].empty()) make_str(s + '1', a, b + 1, c, d,1); break; case '1' : if(c<20&&DP[a][b][c+1][d][0].empty()) make_str(s + '0', a, b, c + 1, d,0); if(d<20&&DP[a][b][c][d+1][1].empty()) make_str(s + '1', a, b, c, d + 1,1); break; default: break; } } int main(int argc, char** argv) { register int i,A,B,C,D; int TC; scanf("%d",&TC); make_str("0",0,0,0,0,0); make_str("1",0,0,0,0,1); for (i = 1; i<=TC; i++) { scanf("%d %d %d %d",&A,&B,&C,&D); DP[A][B][C][D][0].empty() ? (DP[A][B][C][D][1].empty() ? printf("#%d impossible\n",i) : printf("#%d %s\n",i,DP[A][B][C][D][1].c_str())) : printf("#%d %s\n",i,DP[A][B][C][D][0].c_str()); } }
|