描述
示例
算法思路1
答案1
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int wa = scanner.nextInt();
int wb = scanner.nextInt();
int wt = scanner.nextInt();
int pa = scanner.nextInt();
int pb = scanner.nextInt();
System.out.println(GetProfit(wa,wb,wt,pa,pb));
System.exit(0);
}
private static int GetProfit(int wa, int wb,int wt,int pa,int pb) {
if(wa>wt||wb>wt) return 0;
int a = wt/wa;
int b= wt/wb;
int profit=0;
for(int i=1;i<a;i++){
for(int j=1;j<b;j++){
if(wa*i+wb*j==wt){
profit=Math.max(pa*i+pb*j,profit);
}
}
}
return profit;
}
}
详解1
没什么好说的,比较简单,我这种菜菜都秒出,要是所有题都这么简单就好啦(哭得很大声)!!