The idea of the problem is very difficult to think about. Asking the minimum number of experiments you need is very difficult to solve. And we know that there are only three conditions. K, N, number of experiments.
So we'd better change our mind and turn to the highest number of floors we can determine. Then use D[I][J] to indicate the maximum number of floors that can be determined with the I-ball and the J-time of the experiment.
So if we're on the K-floor, there are two possibilities: 1, the ball is broken. So how does the state shift? Using a ball, I used an experimental opportunity. So the best case must be transferred from d[i-1][j-1], so this time the experiment can determine the maximum number of floors is d[i-1][j-1] + 1; 2, the ball is not broken. So the cost is only a chance to use an experiment, so up to the highest can still determine the d[i][j-1] layer.
This d[i][j] successfully transfers the state to the optimal solution of the sub-state. Then this will also be the optimal solution, as they have similar structures.
The code is as follows:
#include <bits/stdc++.h>using namespace std;unsigned long long k,n,d[105][65];int main () {while (cin>> k>>n&&k) { memset (d,0,sizeof (d)); for (int i=1;i<=k;i++) {for (int j=1;j<=64;j++) { d[i][j] = d[i-1][j-1] + 1 + d[i][j-1]; } } int ans = 0; for (int i=64;i>=1;i--) {//Search minimum number of experiments. Suppose 64 satisfies the condition. The experiment number limit if (D[k][i] < n) {ans = i+1; break;} if (d[k][i] = = N) {ans = i; break;} } if (ans<=63) printf ("%d\n", ans); else printf ("More than Trials needed.\n"); } return 0;}
10934-dropping Water Balloons (DP)