2016年8月27日星期六

Egg Dropping Puzzle

Problem
     Egg Dropping Puzzle
Solution
     maxmin
Code


#include <cstring>
#include <stdio.h>
#include <iostream>
using namespace std;

int T;
const int N = 55;
const int M = 1010;
int dp[N][M];
//dp[i][j] = min(max(dp[i - 1][x - 1],dp[i][j - x]));
int main() {
    scanf("%d",&T);
    memset(dp,0x3f,sizeof(dp));
    for (int i = 0;i <= 50;i ++) {
        dp[i][0] = 0;
        dp[i][1] = 1;
    }
    for (int j = 1;j <= 1000;j ++) {
        dp[1][j] = j;
    }

    for (int i = 2;i <= 50;i ++) {
        for (int j = 2;j <= 1000;j ++) {
            for (int k = 1;k <= j;k ++) {
                dp[i][j] = min(dp[i][j],max(dp[i - 1][k - 1],dp[i][j - k]) + 1);
            }
        }
    }
    while (T --) {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        printf("%d %d\n",a,dp[b][c]);
    }
}

没有评论:

发表评论