Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

晕了,怎么WA了,我写的可是标准的DP,竟然错了!~~~`

Posted by hezelin at 2006-11-09 09:22:52 on Problem 1948
#include <iostream>
#include <math.h>
using namespace std;
#define Maxn 41
int main()
{
	int n ;
	int L[ Maxn ] ;
    bool Dp[Maxn][Maxn][Maxn];
	while (cin>>n){
	int i,Len=0;
	for (i=0;i<n;i++) {
		 cin>>L[i];
		 Len+=L[i];
	}
	memset(Dp,0,sizeof(Dp));
	Dp[0][0][0]=1;
	double Maxi,vi,vj;
	int j,k,v;
	for (i=1;i<=n;i++)
		for (j=0;j<Maxn;j++)
			for (v=0;v<Maxn;v++)
				{
				if (j-L[i-1]>=0&&!Dp[i-1][j-L[i-1]][v]) {
					Dp[i][j][v]=1;
					k=Len-j-v;
					if (j+v>k&&j-v<k&&k+j>v){
					double x,p;
					p=(double)(Len/2);
					x=sqrt(p*(p-j)*(p-v)*(p-k));
                    if (x>Maxi) {
						         Maxi=x;
								 vi=j;
								 vj=v;
					}
					}
				}
                    if (v-L[i-1]>=0&&!Dp[i-1][j][v-L[i-1]])  {
					Dp[i][j][v]=1;
					k=Len-j-v;
					if (j+v>k&&j-v<k&&k+j>v){
					double x,p;
					p=(double)(Len/2);
					x=sqrt(p*(p-j)*(p-v)*(p-k));
                    if (x>Maxi) {
						         Maxi=x;
								 vi=j;
								 vj=v;
					}
					}
				}
				}
    if (Maxi!=0) cout<<floor(Maxi*100)<<endl;
	else cout<<-1<<endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator