UVA 10934 filled with water balloons

Source: Internet
Author: User

Test instructions and ideas see:

Http://blog.csdn.net/shuangde800/article/details/11273123

My thoughts are:

First of all, the problem.

Translate the question into: define F[I][J] for the I water polo and J-Test opportunities, up to a few layers ~

Then there is the following transfer equation:

F[I][J] = f[i][j-1] + f[i-1][j-1] + 1;

The latter part is said to be selected in the first level K test, if broken, indicating that the boundary in the following layer.

So the choice of the K-layer, K maximum should meet K <= F[i-1][j-1] + 1; Because to ensure that once the water polo is broken in the K layer, all the layers below can be measured when there are i-1 balls and j-1 times.

The previous section said that the first test was chosen on the K-level, but the ball did not break. At this time the highest is on the basis of the K-layer, plus I ball and j-1 the opportunity to be able to measure a few layers ~ namely f[i][j-1];

So in the two parts, f[i][j] max is equal to F[i-1][j-1] + 1 + f[i][j-1];

Code

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std;long long f[110][65];void init () {      memset (f, 0, sizeof (f));      for (int i = 1;  I < 64; i++) {for            (int j = 1; J <; J + +) {                  f[i][j] = f[i][j-1] + 1 + f[i-1][j-1];}}      } int main () {      init ();      int k;      Long long N;      while (scanf ("%d%lld", &k,&n)! = EOF) {            if (k = = 0) break;            k = min (k, n);            bool OK = false;            for (int i = 0; I <=, i++) {                  if (F[k][i] >= N) {                        printf ("%d\n", I);                        OK = true;                        break;                  }            }            if (!ok) printf ("More than Trials needed.\n");      }      return 0;}




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

UVA 10934 filled with water balloons

Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.