参考代码:
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二级辅导-求偶数和 (C语言代码)浏览:603 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:689 |
printf基础练习2 (C语言代码)浏览:567 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:611 |
分糖果 (C++代码)浏览:1438 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:559 |
C语言训练-计算t=1+1/2+1/3+...+1/n (C语言代码)浏览:904 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:526 |
【明明的随机数】 (C语言代码)浏览:785 |
C语言考试练习题_保留字母 (C语言代码)浏览:700 |