Created
November 11, 2017 14:11
-
-
Save krofna/ee31f238e7e7f968983fc132eb7f324f to your computer and use it in GitHub Desktop.
insane.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int bt(int pos, int cur, int used) | |
{ | |
if (pos == n) | |
return used == 7 ? 0 : 150000 * 5; | |
if (cur != -1 && D[pos][used][cur] != 0) | |
return D[pos][used][cur]; | |
int bs = 5 * 150000; | |
for (int i = 0; i < 3; ++i) | |
if (!(used & 1 << i) || i == cur) | |
bs = min(bs, A[i][pos] + bt(pos + 1, i, used | 1 << i)); | |
return cur != -1 ? D[pos][used][cur] = bs : bs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment