RQNOJ 107 Ural的鹰蛋实验 解题报告

  f[i][j] = min{max{f[k - 1][j], f[i - k][j - 1]} + 1};

  然后因为最多1000,2^10=1024所以超过10个蛋都没用了,所以就if(m > 10){m = 10;}

  代码:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define max(a, b) ((a)>(b)?(a):(b))
int f[1001][1001];

void deal(int m, int n)
{
	int t, s;
	int i, j, k;
	if(m > 10){
		m = 10;
	}
	for(i = 0; i <= n; i++){
		f[i][1] = i;
	}
	for(i = 1; i <= m; i++){
		f[1][i] = 1;
	}
	for(i = 2; i <= n; i++){
		for(j = 2; j <= m; j++){
			s = 0xFFFFFFF;
			for(k = 1; k <= i; k++){
				t = max(f[k - 1][j], f[i - k][j - 1]) + 1;
				if(s > t){
					s = t;
				}
			}
			f[i][j] = s;
		}
	}
	printf("%d\n", f[n][m]);
}

int main(int argc, char **argv)
{
	int i, j;
	while(scanf("%d%d", &i, &j) == 2){
		deal(i, j);
	}
	return 0;
}

  

posted @ 2011-08-25 18:29  zqynux  阅读(312)  评论(0编辑  收藏  举报