POJ1862 Stripies - 贪心法 - 数学推导

Stripies

Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 23136   Accepted: 10062

Description

Our chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian - polosatiki, but the scientists had to invent an English name to apply for an international patent). The stripies are transparent amorphous amebiform creatures that live in flat colonies in a jelly-like nutrient medium. Most of the time the stripies are moving. When two of them collide a new stripie appears instead of them. Long observations made by our scientists enabled them to establish that the weight of the new stripie isn’t equal to the sum of weights of two disappeared stripies that collided; nevertheless, they soon learned that when two stripies of weights m1 and m2 collide the weight of resulting stripie equals to 2sqrt(m1m2). Our chemical biologists are very anxious to know to what limits can decrease the total weight of a given colony of stripies.
You are to write a program that will help them to answer this question. You may assume that 3 or more stipies never collide together.

Input

The first line of the input contains one integer N (1 <= N <= 100) - the number of stripies in a colony. Each of next N lines contains one integer ranging from 1 to 10000 - the weight of the corresponding stripie.

Output

The output must contain one line with the minimal possible total weight of colony with the accuracy of three decimal digits after the point.

Sample Input

3
72
30
50

Sample Output

120.000

 
 

题目大概意思:

有由 N N 1 N 100 1≤N≤100 )个数组成的集合,进行 ( N 1 ) (N-1) 次合并操作,设合并的两个数分别为 a a b b ,则合并后的数 c = 2 a b c=2\sqrt{ab} ,合并后在原集合中删去 a a b b ,并加入 c c ,求进行 ( N 1 ) (N-1) 次合并操作后,集合中剩余的一个数最小是多少。

 
 

分析:

由于合并与顺序相关,故此问题无法运用动态规划解决。那么首先我们借助样例并进行推理,容易证明在 N = 3 N=3 的简单情况下,先合并较大的两个数可以得到最优解。那么接下来证明 N > 3 N>3 的情况:

设集合中的 N N 个元素分别为 a i ( 1 i N ) a_i(1≤i≤N) ,那么我们以任意顺序合并 ( N 1 ) (N-1) 次,最终会得到一个根式的连乘的形式:

S = 2 N 1 a N 2 N 1 i = 1 N 1 2 i a i 2 i = 2 N 1 2 N 1 a N 2 N 1 i = 1 N 1 ( 2 i 2 i a i 2 i ) S=\sqrt[2^{N-1}]{2^{N-1}a_N}·\prod_{i=1}^{N-1}{\sqrt[2^i]{2^ia_i}}=\sqrt[2^{N-1}]{2^{N-1}}·\sqrt[2^{N-1}]{a_N}·\prod_{i=1}^{N-1}(\sqrt[2^i]{2^i}·\sqrt[2^i]{a_i})

观察此式,发现连乘符号 \prod 中的项为 2 i 2^i 2 i 2^i 重根乘以第 i i 个元素的 2 i 2^i 重根, \prod 前的项为 2 N 1 2^{N-1} 2 N 1 2^{N-1} 重根乘以第 N N 个元素的 2 N 1 2^{N-1} 重根,即与连乘中的第 ( N 1 ) (N-1) 项保持相同的形式。

接下来容易发现:

设:

f ( x , y ) = 2 x 2 x y 2 x , f(x,y)=\sqrt[2^x]{2^x}·\sqrt[2^x]{y},
g ( x ) = 2 x 2 x , g(x)=\sqrt[2^x]{2^x},
h ( x , y ) = y 2 x , h(x,y)=\sqrt[2^x]{y},

f ( x , y ) = g ( x ) h ( x , y ) f(x,y)=g(x)·h(x,y) .

易证当 x [ 0 , + ) , y [ 0 , + ) x\in[0,+∞),y\in[0,+∞) 时, g ( x ) > 0 , h ( x , y ) > 0 , g ( x ) < 0 , h x ( x , y ) < 0 , g(x)>0,h(x,y)>0,g'(x)<0,h'_x(x,y)<0,

f x ( x , y ) = g ( x ) h x ( x , y ) + g ( x ) h ( x , y ) < 0 f'_x(x,y)=g(x)·h'_x(x,y)+g'(x)·h(x,y)<0 .

由于 S = f ( N 1 , a N ) i = 1 N 1 f ( i , a i ) S=f(N-1,a_N)·\prod_{i=1}^{N-1}{f(i,a_i)} ,因此将较大的 y y 代入 x x 较大的 f ( x , y ) f(x,y) 可以得到更小的 S S .

所以,我们应从大向小合并。

 
 

下面贴代码:

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

const int MAX_N = 105;

double w[MAX_N];

int main()
{
	int N;

	scanf("%d", &N);
	for (int i = 0; i < N; ++i)
	{
		scanf("%lf", w + i);
	}
	sort(w, w + N);

	for (int i = 1; i < N; ++i)
	{
		w[N - i - 1] = 2 * sqrt(w[N - i - 1] * w[N - i]);
	}
	printf("%.3lf\n", w[0]);

	return 0;
}

原创文章 42 获赞 22 访问量 3054

猜你喜欢

转载自blog.csdn.net/weixin_44327262/article/details/97624258