Zoj 1503-one person "The Price Is Right"

Source: Internet
Author: User

Question: there is a number for you to guess. You have k chances and K insurances. If the guess is low, you will be high and low,

If it is too high, it will tell you that it is too high and you lose a K of insurance (k = 0 when it is too high, it will fail). Now you can ask the number range you can guess.

Analysis: DP, two-dimensional dynamic planning. DP is incremented by the insurance K and the guess lead n.

Status: F (G, L) indicates a chance to have a G guess. The value range is 1 ~ N );

Transfer equation: F (G, L) = g (G-1, L) + 1 + f (G-1, L-1) {Guess low + guess high };

Boundary Condition: If there is no chance of failure, you can only guess from 1;

Note ).

#include <iostream>#include <cstdlib>using namespace std;long long F[ 31 ][ 31 ];int main(){    for ( long long i = 0 ; i <= 30 ; ++ i )        F[ i ][ 0 ] = i;    for ( int i = 0 ; i <= 30 ; ++ i )        F[ 0 ][ i ] = 0L;    for ( int i = 1 ; i <= 30 ; ++ i )    for ( int j = 1 ; j <= 30 ; ++ j )        F[ i ][ j ] = F[ i-1 ][ j ]+F[ i-1 ][ j-1 ]+1;    int G,L,C = 1;    while ( cin >> G >> L && ( G || L ) )        cout << "Case " << C++ << ": " << F[ G ][ L ] << endl;    return 0;}


Zoj 1503-one person "The Price Is Right"

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.