参考代码:
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]; for (int i = 0; i < n; i++) { ar[i] = sc.nextInt(); } int[] dp = new int[200000]; dp[0] = 0; int m = 0,count = 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){ count++; m = 0; }else { m++; if (m > 1000){ System.out.println(count); return; } } } System.out.println("INF"); } }
0.0分
1 人评分
C语言训练-计算1~N之间所有奇数之和 (C语言代码)浏览:644 |
Pascal三角 (C语言代码)格式错误浏览:516 |
妹子杀手的故事 (C语言代码)浏览:1218 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:517 |
WU-图形输出 (C++代码)浏览:801 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:535 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:609 |
1157题解浏览:711 |
P1000 (C语言代码)浏览:869 |
愚蠢的摄影师 (C++代码)浏览:934 |