[UVA][dp] 882 - The Mailbox Manufacturers Problem@Morris' Blog|PChome Online 人新台
2013-06-28 10:28:45| 人1,960| 回1 | 上一篇 | 下一篇

[UVA][dp] 882 - The Mailbox Manufacturers Problem

0 收藏 0 0 站台

The Mailbox Manufacturers Problem

 

In the good old days when Swedish children were still allowed to blow up their fingers with fire-crackers, gangs of excited kids would plague certain smaller cities during Easter time, with only one thing in mind: To blow things up. Small boxes were easy to blow up, and thus mailboxes became a popular target. Now, a small mailbox manufacturer is interested in how many fire-crackers his new mailbox prototype can withstand without exploding and has hired you to help him. He will provide you with k (1<=  k<=10) identical mailbox prototypes each fitting up to m (1<=m<=100)  crackers. However, he is not sure of how many fire-crackers he needs to provide you with in order for you to be able to solve his problem, so he asks you. You think for a while and then say: ”Well, if I blow up a mailbox I can’t use it again, so if you would provide me with only k = 1 mailboxes, I would have to start testing with 1 cracker, then 2 crackers, and so on until it finally exploded. In the worst case, that is if it does not blow up even when filled with m crackers, I would need 1 + 2 + 3 + ... + m = m * (m + 1)/2 crackers. If m = 100 that would mean more than 5000 fire-crackers!”. ”That’s too many”, he replies. ”What if I give you more than k = 1 mailboxes? Can you find a strategy that requires less crackers?”

 

Can you? And what is the minimum number of crackers that you should ask him to provide you with?

You may assume the following:

 

1. If a mailbox can withstand x fire-crackers, it can also withstand x-1 fire-crackers.

2. Upon an explosion, a mailbox is either totally destroyed (blown up) or unharmed, which means that it can be reused in another test explosion.

Note: If the mailbox can withstand a full load of m fire-crackers, then the manufacturer will of course be satisfied with that answer. But otherwise he is looking for the maximum number of crackers that his mailboxes can withstand.

 

Input specifications

The input starts with a single integer N(1<=N<=10) indicating the number of test cases to follow. Each test case is described by a line containing two integers: k and m, separated by a single space.

 

Output specifications

For each test case print one line with a single integer indicating the minimum number of fire-crackers that is needed, in the worst case, in order to figure out how many crackers the mailbox prototype can withstand.

 

Sample input

4

1 10

1 100

3 73

5 100

 

Output for sample input

55

5050

382

495



目描述:

在有 k 箱(?),每箱共同有一最低下限的炸可以被引爆,在已知道一次最多放 m 炸,在只能使用 k 箱行找到最低下限,最小的炸量是多少。

目解法:

使用 dp[i][j][k] 在只剩下 i 箱可以, 已知道炸介於 j ~ k。
下次使用的炸量, 因此分成炸掉或者炸掉, 者取最大使用量的。


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int dp[15][105][105];
int used[15][105][105];
#define oo 0xfffffff
int dfs(int k, int l, int r) {
    if(l == r)  return 0;
    if(k == 0)  return oo;
    if(used[k][l][r])
        return dp[k][l][r];
    used[k][l][r] = 1;
    int i;
    int &ret = dp[k][l][r];
    ret = oo;
    for(i = l+1; i <= r; i++)
        ret = min(ret, i+max(dfs(k-1, l, i-1),dfs(k, i, r)));
    return ret;
}
int main() {
    memset(used, 0, sizeof(used));
    int testcase, k, m;
    scanf("%d", &testcase);
    while(testcase--) {
        scanf("%d %d", &k, &m);
        printf("%d\n", dfs(k, 0, m));
    }
    return 0;
}

台: Morris
人(1,960) | 回(1)| 推 (0)| 收藏 (0)|
全站分: 不分 | 人分: UVA |
此分下一篇:[UVA][dp] 222 - Budget Travel
此分上一篇:[UVA] 815 - Flooded!

sayo
可以解一下?>////<
我不太懂
2016-11-24 17:11:56
是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86