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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
| #include <iostream> #include <algorithm> #include <vector>
using namespace std; class Horse{ public: int x; int y; bool run; int status; }; int dice[10]; int map[9][9] = {{40, 0 , 0, 0, 38, 36, 34, 32, 30}, {0 , 0 , 0, 0, 0, 0, 0, 28, 0}, {0 , 0 , 35, 0, 0, 0, 27, 0, 0}, {0 , 0 , 0, 30, 0, 26, 0, 0, 0}, {2 , 0 , 0, 0, 25, 0, 0, 0, 28}, {4 , 0 , 0, 19, 0, 24, 0, 0, 26}, {6 , 0 , 16, 0, 0, 0, 22, 0, 24}, {8 , 13, 0, 0, 0, 0, 0, 0, 22}, {10, 12, 14, 16, 18, 0, 0, 0, 20}}; int score = 0; int ans = 0; Horse horse[4]; int choose[10]; bool flag;
bool move(int c_h,int mv){ if(horse[c_h].status>10){ flag = false; return false; } int x = horse[c_h].x; int y = horse[c_h].y; int st = horse[c_h].status; int mvc = mv; while(1){ if(mvc == 0) break; if(st==1){ y++; while(map[y][x]==0){ y++; } } else if(st==2){ x++; while(map[y][x]==0){ x++; } } else if(st==3){ y--; while(map[y][x]==0){ y--; } } else if(st==4){ x--; while(map[y][x]==0){ x--; } } else if(st==5){ x++; y--; while(map[y][x]==0){ x++; y--; } } else if(st==6){ x--; y--; while(map[y][x]==0){ x--; y--; } } else if(st==7){ x--; y++; while(map[y][x]==0){ x--; y++; } } else if(st==8){ if(x==0&&y==0){ horse[c_h].status = 987654321; horse[c_h].run = false; } x--; y--; while(map[y][x]==0){ x--; y--; } }
if(y==4&&x==4){ st = 8; } else if(x==0&&y==8){ st=2; } else if(x==8&&y==8){ st=3; } else if(x==8&&y==0){ st=4; } mvc--; } if(x<0||y<0){ horse[c_h].status = 987654321; horse[c_h].run = false; return false; } if(x==0&&y==8) st = 5; else if(x==8&&y==8) st = 6; else if(x==8&&y==0) st = 7; else if(y==4&&x==4) st = 8; for(int i=0;i<4;i++) { if(horse[i].x==x&&horse[i].y==y&&horse[i].run&&horse[c_h].status<10){ flag = false; return false; } } horse[c_h].x = x; horse[c_h].y = y; horse[c_h].status = st; score += map[y][x]; return true; } void dfs(int depth){ if(depth==10){ for(int i=0;i<4;i++){ horse[i].x = 0; horse[i].y = 3; horse[i].run = false; horse[i].status = 1; } score = 0; flag = true; for(int i=0;i<10;i++){ horse[choose[i]].run = true; } for(int i=0;i<10;i++){ if(flag) move(choose[i], dice[i]); else return; } if(flag) ans = max(ans,score); return ; }
for(int i=0;i<4;i++){ choose[depth]=i; dfs(depth+1); } } int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
for(int i=0;i<10;i++) cin>>dice[i];
dfs(0); cout<<ans<<endl;
}
|