Luogu1268 树的重量

思路!好题!太神奇了!

推荐这篇

CODE:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline int qr(){
	int x=0;
	char ch=getchar();
	for(;!isdigit(ch); ch=getchar());
	for(; isdigit(ch); ch=getchar()) x=(x<<3)+(x<<1)+ch-48;
	return x;
}
int n,a[31][31],ans,tmp;
int main(){
	while(scanf("%d",&n)!=EOF && n){
		for(int i=1; i<=n-1; i++)
			for(int j=i+1; j<=n; j++)
				a[i][j]=a[j][i]=qr();
		ans=a[1][2];
		for(int i=3; i<=n; i++){
			tmp=0x7fffffff;
			for(int j=1; j<=i-1; j++) 
				for(int k=1; k<=j-1; k++)
					tmp=min(tmp,(a[j][i]+a[k][i]-a[j][k])>>1);
			ans+=tmp;
		}
		printf("%d\n",ans);
	}
	return 0;
}

posted @ 2018-11-05 19:54  PushinL  阅读(141)  评论(0编辑  收藏  举报