10934-dropping Water Balloons (DP)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.