UVa882 The Mailbox Manufacturers Problem

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 (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 cant use it again, so if you would provide me with only = 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 crackers, I would need 1 + 2 + 3 + ... + (m + 1)/2 crackers. If = 100 that would mean more than 5000 fire-crackers!. Thats too many, he replies. What if I give you more than = 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 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 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: 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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
const int INF = 1e9;
int dp[12][110][110];
int n,k;
int dfs(int dep,int sta,int ed){
    if(dp[dep][sta][ed] != -1)
        return dp[dep][sta][ed];
    if(sta>ed) return  0;
    int ans = INF;
    for(int k = sta; k <= ed; k++)
        ans = min(ans,k+max(dfs(dep,k+1,ed),dfs(dep-1,sta,k-1)));
    return dp[dep][sta][ed] = ans;
}
int main(){

    memset(dp, -1,sizeof dp);
    for(int j = 1; j <= 100; j++)
        for(int k = j; k <= 100; k++)
            dp[1][j][k] = (j+k)*(k-j+1)/2;
    int ncase;
    cin >> ncase;
    while(ncase--){
        scanf("%d%d",&n,&k);
        cout<<dfs(n,1,k)<<endl;
    }
    return 0;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值