import java.util.Scanner;
public class Main {
static int maxn = 300000;
static int[] dp = new int[maxn];
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
boolean flag = false;
for(int i = 0;i<n;i++){
arr[i] = sc.nextInt();
if(arr[i] == 1){
flag = true;
}
}
if(flag){
System.out.println(0);
}else {
int temp = arr[0];
for(int i = 1;i<n;i++){
temp = gcd(temp,arr[i]);
}
int ans = 0;
int count = 0;
if(temp == 1){
dp[0] = 1;
for(int i = 0;i<n;i++){
for(int j = arr[i];j < maxn;j++){
if(dp[j - arr[i]] == 1){
dp[j] = 1;
}
}
}
for(int k = maxn - 1;k >= 0;k--){//求出最大的不能组合出来的体积
if(dp[k] == 0){
ans = k;
break;
}
}
for(int p = 1;p <= ans;p++){//求组合不出来的体积的个数(不包括0)
if(dp[p] == 0){
count++;
}
}
System.out.println(ans);
System.out.println(count);
}else{
System.out.println(0);
}
}
}
public static int gcd(int a,int b){
return b == 0 ? a : gcd(b,a%b);
}
}
试题 算法训练 最大体积 Java
最新推荐文章于 2024-08-16 23:08:28 发布