记录编号 294444 评测结果 AAAAAAA
题目名称 [HZOI 2014] 合并石子 最终得分 100
用户昵称 GravatarNewBee 是否通过 通过
代码语言 C++ 运行时间 0.010 s
提交时间 2016-08-12 07:08:16 内存使用 0.66 MiB
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<algorithm>
#define Cu chul();fclose(stdin);fclose(stdout);return 0;
#define  Begin() freopen("stone2.in","r",stdin);freopen("stone2.out","w",stdout);Cu;
using namespace std;
//designed by New_Beeؼ 
const int maxn=220;
int fmax[maxn][maxn],fmin[maxn][maxn];
int qzh[maxn],a[maxn];
void chul(){
	memset(fmin,63,sizeof(fmin));
	int n;scanf("%d",&n);int maxx=0,minn=0x7fffffff;
	for(int i=0;i<=n*2;i++)fmin[i][i]=0;
	for(int i=1;i<=n;i++){scanf("%d",&a[i]);qzh[i]=qzh[i-1]+a[i];}
	for(int i=n+1;i<=2*n;i++)qzh[i]=qzh[i-1]+a[i-n];
	for(int d=2;d<=n;d++){
		for(int i=1;i+d-1<=2*n;i++){
			int j=i+d-1;
			for(int k=i;k<=j;k++){
				fmax[i][j]=max(fmax[i][j],fmax[i][k]+fmax[k+1][j]+qzh[j]-qzh[i-1]);
				fmin[i][j]=min(fmin[i][j],fmin[i][k]+fmin[k+1][j]+qzh[j]-qzh[i-1]);	
			}if(d==n){
				maxx=max(maxx,fmax[i][j]);
				minn=min(minn,fmin[i][j]);
			}
		}
	}printf("%d\n%d",minn,maxx/2);
}
int main(){
	Begin();
}