Skip to content

Instantly share code, notes, and snippets.

@krofna
Created November 11, 2017 14:11
Show Gist options
  • Save krofna/ee31f238e7e7f968983fc132eb7f324f to your computer and use it in GitHub Desktop.
Save krofna/ee31f238e7e7f968983fc132eb7f324f to your computer and use it in GitHub Desktop.
insane.cpp
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