参考代码:
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] ar = new int[n]; int[] dp = new int[1000000]; for (int i = 0; i < n; i++) { ar[i] = sc.nextInt(); } dp[0] = 0; int count = 0; int m = 0; for (int i = 1; i < dp.length; i++) { dp[i] = Integer.MAX_VALUE; for (int j = 0; j < ar.length; j++) { if (i >= ar[j] && dp[i-ar[j]] != Integer.MAX_VALUE){ dp[i] = Math.min(dp[i - ar[j]],dp[i]); } } if (dp[i] == Integer.MAX_VALUE){ m = i; count = 0; }else { count++; if (count > 5000){ System.out.println(m); return; } } } System.out.println(0); } }
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:568 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:481 |
2005年春浙江省计算机等级考试二级C 编程题(3) (C语言代码)浏览:388 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:468 |
淘淘的名单 (C语言代码)浏览:1090 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:581 |
IP判断 (C语言描述,蓝桥杯)浏览:1094 |
a+b浏览:432 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:668 |
1014题解浏览:484 |