2022-04-25 14:37
广西大学 Java 牛客27401890...:public class ApplePear {
private static Combo c1,c2;
private static int aPrice,pPrice;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int apple = 0, pear = 0;
String[] fs = br.readLine().split(" ");
apple = Integer.parseInt(fs[0]);
pear = Integer.parseInt(fs[1]);
if (apple == 0 &;&; pear == 0) {
System.out.println(0);
return;
}
String[] prices = br.readLine().split(" ");
aPrice = Integer.parseInt(prices[0]);
pPrice = Integer.parseInt(prices[1]);
String[] com1 = br.readLine().split(" ");
c1 = new Combo(
Integer.parseInt(com1[0]),
Integer.parseInt(com1[1]),
Integer.parseInt(com1[2]) );
String[] com2 = br.readLine().split(" ");
c2 = new Combo(
Integer.parseInt(com2[0]),
Integer.parseInt(com2[1]),
Integer.parseInt(com2[2]) );
int res = dfs(apple, pear);
System.out.println(res);
}
private static int dfs(int apple, int pear) {
if (apple == 0 &;&; pear == 0) {
return 0;
}
if (apple == 0 &;&; pear != 0) {
return dfs(0, pear-1) + pPrice;
} else if (apple != 0 &;&; pear == 0) {
return dfs(apple-1, 0) + aPrice;
} else {
if (c1.isOk(apple, pear)) {
int valTao = dfs(apple - c1.apple, pear - c1.pear) + c1.prices;
return valTao;
} else if (c2.isOk(apple, pear)) {
int valTao = dfs(apple - c2.apple, pear - c2.pear) + c2.prices;
return valTao;
} else {
return dfs(apple-1, pear-1) + aPrice + pPrice;
}
}
}
private static class Combo {
public final int apple;
public final int pear;
public final int prices;
public Combo (int apple, int pear, int prices) {
this.apple = apple;
this.pear = pear;
this.prices = prices;
}
public boolean isOk(int apple, int pear) {
if (apple >= this.apple &;&; pear >= this.pear) {
return true;
}
return false;
}
}
}

0 点赞 评论 收藏
分享
创作者周榜
更多
关注他的用户也关注了: