lightoj-1223-Testing Mailboxes 区间dp

1223 - Testing Mailboxes
Time Limit: 2 second(s)Memory Limit: 32 MB

When monkeys are given some fire-crackers, they have only thing in the 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 identical mailbox prototypes each fitting up to m fire-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 your help.

The constraints are:

1.      If you blow up a mailbox, you can't use the mailbox again, so if you have only k = 1 mailboxes, you would have to start testing with 1 fire-cracker, then 2 fire-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 fire-crackers, you would need 1 + 2 + 3 + ... + m = m * (m + 1)/2 fire-crackers.

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

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

Now the manufacturer wants you to find the maximum number of fire-crackers that his mailboxes can withstand. Before doing that you have to buy some fire-crackers to test that. So, you need to find the minimum number of fire-crackers you need to buy to test the mailboxes.

Input

Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case starts with a line containing two integers: k (1 ≤ k ≤ 100) and m (1 ≤ m ≤ 100).

Output

For each case, print the case number and the minimum number of fire-crackers you have to buy.

Sample Input

Output for Sample Input

4

1 10

3 73

5 100

1 100

Case 1: 55

Case 2: 382

Case 3: 495

Case 4: 5050

 


和poj3783有些像,有两种决策,破了和没破。


#include <bits/stdc++.h>
//#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

#define ll long long
#define SZ(x) ((int)(x).size()) 
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define reveach(i, v) for (__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++ i) 
#define REP(i,a,n) for ( int i=a; i<int(n); i++ )
#define FOR(i,a,n) for ( int i=n-1; i>= int(a);i-- )
#define lson rt<<1, L, m
#define rson rt<<1|1, m, R
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fi first
#define se second
#define CLR(a, b) memset(a, b, sizeof(a))
#define Min(a, b) a = min(a, b)
#define Max(a, b) a = max(a, b)
const int maxn = 1e2 + 7;
const int INF = 0x3f3f3f3f;
int T;
int kase;
int n, m;
int dp[maxn][maxn][maxn];
void ini(){
    CLR(dp, 0);
    REP(j, 1, 101){
        dp[1][j][j] = j;
        REP(k, j+1, 101) dp[1][j][k] = dp[1][j][k-1] + k;
    }
    REP(i, 1, 101){
        REP(t, 0, 100){
            REP(j, 1, 101){
                int k = j + t;
                dp[i][j][k] = INF;
                REP(l, j, k+1){
                    Min(dp[i][j][k], max(dp[i][l+1][k], dp[i-1][j][l-1])+l);
                }
            }
        }
    }
}
int main(){
#ifdef ac
    freopen("in.txt","r",stdin);
#endif
    //freopen("out.txt","w",stdout);
    scanf("%d", &T);
    ini();
    while(T--){
        scanf("%d%d", &n, &m);
        printf("Case %d: %d\n", ++kase, dp[n][1][m]);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值