zoj 1503 - One Person "The Price is Right"

题目:有一个数字让你猜,你有k次机会,并且有k个保险如果猜的低了会高度你低了,

高了会告诉你高了,并且失去一k保险(k=0时猜高了就会失败),现在问你能猜的数字范围。

分析:dp,二维动态规划。按保险k和猜的机会n递增的方向dp。

状态:f(G,L)为有G次猜的机会,L个保险时确定的数字范围(1~N);

转移方程:F(G,L)= G(G-1,L)+ 1 + F(G-1,L-1){ 猜低 + 猜中 + 猜高 };

边界条件:如果没有失败机会的话,只能从1开始向后猜;

说明:(2011-10-03 16:32)。

#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;
}
时间: 2024-08-01 10:41:25

zoj 1503 - One Person "The Price is Right"的相关文章

zoj题目分类

饮水思源---zoj 转载自:http://bbs.sjtu.edu.cn/bbscon,board,ACMICPC,file,M.1084159773.A.html 注:所有不是太难的题都被归成了“简单题”,等到发现的时候已经太晚了,我太死脑筋 了……:( 有些题的程序我找不到了,555……:( SRbGa的题虽然都很经典……但是由于其中的大部分都是我看了oibh上的解题报告后做 的,所以就不写了…… 题目排列顺序没有规律……:( 按照个人感觉,最短路有的算做了DP,有的算做了图论. 有些比较

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

ZOJ 3333 Guess the price

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3758 题面: Guess the Price Time Limit: 1 Second      Memory Limit: 32768 KB In the television program "Shopping Street" of CCTV-2, two people, A and B are guessing price of a given it

ZOJ 3607 Lazier Salesgirl (贪心)

Lazier Salesgirl Time Limit: 2 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling. She can sell the i-th customer a piece of bread for price pi. But she is so lazy

ZOJ 3794 Greedy Driver

Greedy Driver Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 3794 64-bit integer IO format: %lld      Java class name: Main Edward is a truck driver of a big company. His daily work is driving a truck from o

2013 ACM/ICPC 长沙现场赛 A题 - Alice&#39;s Print Service (ZOJ 3726)

Alice's Print Service Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using her print service found some tricks to save money. For example, the price when

HDU 4791 &amp;amp; ZOJ 3726 Alice&amp;#39;s Print Service (数学 打表)

题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5072 Problem Description Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using her pr

HDU 4791 &amp; ZOJ 3726 Alice&#39;s Print Service (数学 打表)

题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5072 Problem Description Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using her pr

ZOJ 1586 QS Network (经典MST~Prim)

链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=586 In the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS. QScommunicate with each other via networks. If two QS want to get connected, they need to buy two n