UVa 10934 DP dropping water balloons

Source: Internet
Author: User

First think about the special situation, if there is only one balloon, we have to determine the height can only from the bottom to the next layer of testing, because if the balloon burst, it will not be able to measure the hardness of the balloon.

If there are countless balloons, then you can use a two-point method to determine.

Generally, a D (i, j) is used to indicate the maximum height of the floor that can be determined by the I-Balloon experiment J-Th.

Let's assume that the first balloon is dropped from level K,

    • If the balloon burst, then the rest of the i-1 a balloon experiment j-1 times, to be able to determine the hardness of the balloon in the K-1 layer below. So this k Max takes D (i-1, j-1) +1
    • The balloon does not explode, then the first 1~k layer is completely out of control, I j-1 the rest of the balloon test will go directly to the test on the line, up to test D (I, j-1) layer

So D (i, j) = d (i-1, j-1) + 1 + d (i, j-1)

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 7typedef unsignedLong LongLL;8 9 Const intMAXN = -+1;Ten Const intMAXM = -; One  A LL A[MAXN][MAXM]; -  - intN; the LL H; -  - intMain () - { +      for(inti =1; i < MAXN; i++) -          for(intj =1; J < Maxm; J + +) +A[I][J] = a[i-1][j-1] +1+ a[i][j-1]; A  at      while(CIN >> N >> H &&N) -     { -         inti; -          for(i =1; i < MAXM; i++)if(A[n][i] >= h) Break; -         if(I < MAXM) printf ("%d\n", i); -         ElsePuts"More than trials needed."); in     } -  to     return 0; +}
code June

UVa 10934 DP dropping water balloons

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.