@@ -0,0 +1,1117 @@
+package test;%0A%0A/*%0Ascala%3E import test.Test._%0Aimport test.Test._%0Ascala%3E val arr = Array(new Enemy(2, 2), new Enemy(1, 1), new Enemy(3, 8), new Enemy(4, 6))%0Ascala%3E test.Test.play(1, 10, arr)%0Ares0: Int = 7%0Ascala%3E test.Test.play(1, 4, arr)%0Ares1: Int = 1%0A*/%0Apublic class Test %7B%0A  public static class Enemy %7B%0A    int strength;%0A    int price;%0A%0A    public Enemy(int strength, int price) %7B%0A      this.strength = strength;%0A      this.price = price;%0A    %7D%0A  %7D%0A%0A  private static int faceEnemy(int strength, int money, Enemy%5B%5D enemies, int i) %7B%0A    if (money %3C 0) return -1;%0A    if (enemies == null %7C%7C enemies.length %3C= i) return money;%0A    Enemy enemy = enemies%5Bi%5D;%0A    int res = -1;%0A    if (strength %3E= enemy.strength) %7B%0A      res = Math.max(res, faceEnemy(strength, money, enemies, i + 1));%0A    %7D%0A    if (money %3E= enemy.price) %7B%0A      res = Math.max(res,%0A        faceEnemy(strength + enemy.strength, money - enemy.price, enemies, i + 1));%0A    %7D%0A    return res;%0A  %7D%0A%0A  public static int play(int strength, int money, Enemy%5B%5D enemies) %7B%0A    money = faceEnemy(strength, money, enemies, 0);%0A    return money %3C 0 ? -1 : money;%0A  %7D%0A%7D%0A

add solution