public class Main { public static void main(String[] args) { System.out.println(solution1(1000, 3)); } public static int solution1(int n, int c) { if (c == 1) { return n; } int[][] dp = new int[n + 1][c + 1]; for (int i = 1; i < n + 1; i++) { dp[i][1] = i;// 当只有一部手机时,其测试次数为楼层数,因为只能一层一层测试 } for (int i = 1; i < n + 1; i++) { for (int j = 2; j < c + 1; j++) { int min = Integer.MAX_VALUE;// 表示int数据类型的最大取值数:2 147 483 647 for (int k = 1; k < i + 1; k++) { min = Math.min(min, Math.max(dp[k - 1][j - 1], dp[i - k][j])); } dp[i][j] = min + 1; } } return dp[n][c]; } }