个体工商户能做网站吗,商业设计方案,最专业 汽车网站建设,上海网站关键词排名优化报价题目描述:
有一个箱子容量为 #x1d449;V#xff0c;同时有 #x1d45b;n 个物品#xff0c;每个物品有一个体积。
现在从 #x1d45b;n 个物品中#xff0c;任取若干个装入箱内#xff08;也可以不取#xff09;#xff0c;使箱子的剩余空间最小。输出这个最小…题目描述:
有一个箱子容量为 V同时有 n 个物品每个物品有一个体积。
现在从 n 个物品中任取若干个装入箱内也可以不取使箱子的剩余空间最小。输出这个最小值。
代码:
package lanqiao;import java.util.*;public class Main {static int N 20010;static int[] f new int[N];public static void main(String[] args) {Scanner sc new Scanner(System.in);int V sc.nextInt(); //箱子容量int n sc.nextInt();for(int i 0;i n;i ){int v sc.nextInt();for(int j V;j v;j --){f[j] Math.max(f[j],f[j - v] v);}}System.out.println(V - f[V]);}
}