We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
DP:
class Solution { public int twoEggDrop(int n) { int egg = 2; // dp[i][j] 表示第i+1个鸡蛋在j层楼确定f的最小次数 int[][] dp = new int[egg][n + 1]; // init for (int i = 0; i < egg; ++i) { Arrays.fill(dp[i], Integer.MAX_VALUE); } dp[0][0] = dp[1][0] = 0; // 因为只有一个鸡蛋,此时只能从下往上一个个试验 for (int j = 1; j <= n; ++j) { dp[0][j] = j; } // k表示第一个鸡蛋在哪一层碎了,不管碎没碎所以先把操作次数+1 // 接着如果碎了,就在下一块区域,此时取得是dp[0][k - 1] // 没碎,取得是上一块区域,为dp[1][j - k] // 因为保证都能取到,所以先求上述两者结果的Max // 接着求f for (int j = 1; j <= n; ++j) { for (int k = 1; k <= j; ++k) { dp[1][j] = Math.min(dp[1][j], Math.max(dp[0][k - 1] + 1, dp[1][j - k] + 1)); } } return dp[1][n]; } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
DP:
The text was updated successfully, but these errors were encountered: