用dfs做的,为什么会全WA啊?
查看原帖
用dfs做的,为什么会全WA啊?
1064396
ALPA楼主2023/10/6 10:33
#include <iostream>
#include <cmath>
using namespace std;
int s[45],n,maxn = 0;
double helen(int a,int b,int c)
{
	if(a == 0 || b == 0 || c == 0)
	{
		return -1;
	}
	double s = 0.5 * (a + b + c);
	return sqrt(s * (s - a) * (s - b) * (s - c));
} 
void dfs(int step,int a,int b,int c)
{
	if(step > n)
	{
		if(int(helen(a,b,c) * 100) > maxn && a + b > c && a + c > b && b + c > a)
		{
			maxn = int(helen(a,b,c) * 100);
		}
		return;
	}
	dfs(step + 1,a + s[step],b,c);
	dfs(step + 1,a,b + s[step],c);
	dfs(step + 1,a,b,c + s[step]);
}
int main()
{
	maxn = 0;
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> s[i];
	}
	dfs(1,0,0,0);
	cout << maxn;
	return 0;
}
2023/10/6 10:33
加载中...