| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:1948怎么背包啊In Reply To:Re:1948怎么背包啊 Posted by:luzilon1 at 2009-03-15 17:43:16 > 先背包算出所有可行边seg1
> 当枚举上面的边的时候要记录那些fence不可用
> 之后背包算出第二条可行边seg2
> seg3 = sum - seg1 - seg2;
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int dp[2000][2000];
int L[40];
int area(double a,double b,double c){
if(a>b) swap(a,b);
if(a>c) swap(a,c);
if(b>c) swap(b,c);
if(a+b<=c) return 0;
double s = (a+b+c)/2;
return floor(100.0*sqrt(s*(s-a)*(s-b)*(s-c)));
}
int main(){
int n;
scanf("%d",&n);
int tot = 0;
for(int i=0;i<n;i++)
scanf("%d",L+i),tot+=L[i];
memset(dp,0,sizeof dp);
dp[0][0] = 1;
for(int i=0;i<n;i++)
for(int j=tot;j>=0;j--)
for(int k=tot;k>=0;k--)
if(dp[j][k])dp[j+L[i]][k] = 1, dp[j][k+L[i]] = 1;
int best = 0;
for(int i=0;i<=tot;i++)
for(int j=0;j<=tot;j++)
if(dp[i][j])
best = max(best,area(i,j,tot-i-j));
if(best==0)printf("-1\n");
else printf("%d\n",best);
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator