public class MutaliskEasy {
int[][][] dpMem;
int dp(int a, int b, int c)
{
if(a < 0) a = 0;
if(b < 0) b = 0;
if(c < 0) c = 0;
if(a+b+c == 0) return 0;
if(dpMem[a][b][c] >= 0) return dpMem[a][b][c];
int ret = 10000;
ret
= Math.
min(ret,
1 + dp
(a
- 9, b
- 3, c
- 1)); ret
= Math.
min(ret,
1 + dp
(a
- 9, b
- 1, c
- 3)); ret
= Math.
min(ret,
1 + dp
(a
- 3, b
- 1, c
- 9)); ret
= Math.
min(ret,
1 + dp
(a
- 3, b
- 9, c
- 1)); ret
= Math.
min(ret,
1 + dp
(a
- 1, b
- 3, c
- 9)); ret
= Math.
min(ret,
1 + dp
(a
- 1, b
- 9, c
- 3)); dpMem[a][b][c] = ret;
return ret;
}
public int minimalAttacks(int[] x)
{
dpMem = new int[61][61][61];
for(int i = 0; i <= 60; i++)
for(int j = 0; j <= 60; j++)
for(int k = 0; k <= 60; k++)
dpMem[i][j][k] = -1;
return dp((x.length > 0 ? x[0] : 0), (x.length > 1 ? x[1] : 0), (x.length > 2 ? x[2] : 0));
}
}
cHVibGljIGNsYXNzIE11dGFsaXNrRWFzeSB7CgoKICAgIGludFtdW11bXSBkcE1lbTsKCiAgICBpbnQgZHAoaW50IGEsIGludCBiLCBpbnQgYykKICAgIHsKICAgICAgICBpZihhIDwgMCkgYSA9IDA7CiAgICAgICAgaWYoYiA8IDApIGIgPSAwOwogICAgICAgIGlmKGMgPCAwKSBjID0gMDsKICAgICAgICBpZihhK2IrYyA9PSAwKSByZXR1cm4gMDsKICAgICAgICBpZihkcE1lbVthXVtiXVtjXSA+PSAwKSByZXR1cm4gZHBNZW1bYV1bYl1bY107CiAgICAgICAgaW50IHJldCA9IDEwMDAwOwogICAgICAgIHJldCA9IE1hdGgubWluKHJldCwgMSArIGRwKGEgLSA5LCBiIC0gMywgYyAtIDEpKTsKICAgICAgICByZXQgPSBNYXRoLm1pbihyZXQsIDEgKyBkcChhIC0gOSwgYiAtIDEsIGMgLSAzKSk7CiAgICAgICAgcmV0ID0gTWF0aC5taW4ocmV0LCAxICsgZHAoYSAtIDMsIGIgLSAxLCBjIC0gOSkpOwogICAgICAgIHJldCA9IE1hdGgubWluKHJldCwgMSArIGRwKGEgLSAzLCBiIC0gOSwgYyAtIDEpKTsKICAgICAgICByZXQgPSBNYXRoLm1pbihyZXQsIDEgKyBkcChhIC0gMSwgYiAtIDMsIGMgLSA5KSk7CiAgICAgICAgcmV0ID0gTWF0aC5taW4ocmV0LCAxICsgZHAoYSAtIDEsIGIgLSA5LCBjIC0gMykpOwogICAgICAgIGRwTWVtW2FdW2JdW2NdID0gcmV0OwogICAgICAgIHJldHVybiByZXQ7CiAgICB9CgogICAgcHVibGljIGludCBtaW5pbWFsQXR0YWNrcyhpbnRbXSB4KQogICAgewogICAgICAgIGRwTWVtID0gbmV3IGludFs2MV1bNjFdWzYxXTsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDw9IDYwOyBpKyspCiAgICAgICAgICAgIGZvcihpbnQgaiA9IDA7IGogPD0gNjA7IGorKykKICAgICAgICAgICAgICAgIGZvcihpbnQgayA9IDA7IGsgPD0gNjA7IGsrKykKICAgICAgICAgICAgICAgICAgICBkcE1lbVtpXVtqXVtrXSA9IC0xOwogICAgICAgIHJldHVybiBkcCgoeC5sZW5ndGggPiAwID8geFswXSA6IDApLCAoeC5sZW5ndGggPiAxID8geFsxXSA6IDApLCAoeC5sZW5ndGggPiAyID8geFsyXSA6IDApKTsKICAgIH0KCn0K