10934-dropping Water Balloons (DP)

Source: Internet
Author: User

The idea of the problem is hard to think about. Ask you the minimum number of experiments, which is difficult to solve, and we know the conditions only three, K, N, the number of experiments.

So we might as well 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.

Then we assume that the first J experiment is on the k floor, there are two possible: 1, the ball is broken, then the state how to transfer? Using a ball, with an experimental opportunity, so the best situation must be transferred from d[i-1][j-1], so this time the experiment can determine the maximum number of floors of d[i-1][j-1] + 1; 2, the ball is not broken, then the cost is only a chance to use an experiment, so up to the highest can still determine 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, because 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, if 64 satisfies the condition, exceeds the experiment number limit if            (D[k][i] < n) {ans = i+1;            if (d[k][i] = = N) {ans = i; break;}        }        if (ans<=63) printf ("%d\n", ans);        else printf ("More than Trials needed.\n");    }    return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.