POJ1948-Triangular Pastures

http://poj.org/problem?id=1948

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int l[44],dp[888][888];
int area(int x,int y,int z)
{
    double p=(x+y+z)/2.0;
    return (int)(sqrt(p*(p-x)*(p-y)*(p-z))*100);
}
int main(void)
{
    int i,j,k,n,m,sum,ans;
    while(scanf("%d",&n)!=EOF)
    {
        for(sum=i=0;i<n;i++)
        {
            scanf("%d",&l[i]);
            sum+=l[i];
        }
        m=sum/2-((sum&1)==0);
        for(i=0;i<=m;i++)
            for(j=0;j<=i;j++)
               dp[i][j]=0;
        dp[0][0]=1;
        for(k=0;k<n;k++)
            for(i=m;i>=0;i--)
                for(j=i;j>=0;j--)
                    if(dp[i][j])
                       dp[i+l[k]][j]=dp[i][j+l[k]]=1;
        ans=-1;
        for(i=1;i<=m;i++)
            for(j=1;j<=i;j++)
                if(dp[i][j])
                   ans=max(ans,area(i,j,sum-i-j));
        printf("%d\n",ans);
    }
    return 0;
}
posted @ 2012-08-31 09:59  Yogurt Shen  阅读(96)  评论(0编辑  收藏  举报