TYVJ 1062 合并傻子 解题报告

  题目一直没看懂,最近终于看懂了题目,不怎么难,就是DP,和石子合并一模一样,不细说了(打工好累,想睡了。)

  代码:

#include <stdio.h>
#include <stdlib.h>
int num[100];
int max_[100][101], min_[100][101];
int sum[100][101];
#define min(a, b) ((a)<(b)?(a):(b))
#define max(a, b) ((a)>(b)?(a):(b))
int rpn = 0xFFFFFFF, rpx;

int main(int argc, char **argv)
{
	int i, j, k;
	int n, m;
	scanf("%d%d", &n, &m);
	for(i = 0; i < n; i++){
		scanf("%d", &num[i]);
	}
	for(i = 0; i < n; i++){
		for(j = 1; j <= n; j++){
			sum[i][j] = sum[i][j - 1] + num[(i + j - 1) % n];
		}
	}
	for(j = 2; j <= n; j++){
		for(i = 0; i < n; i++){
			min_[i][j] = 0xFFFFFFF;
			for(k = 1; k < j; k++){
				max_[i][j] = max(max_[i][j], max_[i][k] + max_[(i + k) % n][j - k] + sum[i][k] + sum[(i + k) % n][j - k]);
				min_[i][j] = min(min_[i][j], min_[i][k] + min_[(i + k) % n][j - k] + sum[i][k] + sum[(i + k) % n][j - k]);
			}
		}
	}
	for(i = 0; i < n; i++){
		if(rpx < max_[i][n]){
			rpx = max_[i][n];
		}
		if(rpn > min_[i][n]){
			rpn = min_[i][n];
		}
	}
	if(m > rpx){
		printf("It is easy\n");
	}else if(m < rpn){
		printf("I am..Sha...X\n");
	}else{
		printf("I will go to play WarIII\n");
	}
	return 0;
}

posted @ 2011-07-11 22:50  zqynux  阅读(341)  评论(0编辑  收藏  举报