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

Posted by lhzlucky at 2006-12-18 15:11:03 on Problem 1015
#include<iostream>
#include<math.h>
using namespace std;
const int nnm=202;
const int mmm=22;
int a[nnm][2],b[nnm][mmm],p[nnm][mmm],h[nnm][mmm];//b保存路径,p保存最优值,h保存D(J) + P(J)
//p[n][m]表示前n人选m个代表的最优的D(J) - P(J)值
void show(int n,int m)
{
	if(n<1||m<1)return;
	if(b[n][m])
	{
		show(n-1,m-1);
		cout<<" "<<n;
	}
	else show(n-1,m);
}
void main()
{
	int s,r,i,n,m,nn,mm,k=0;
	while(cin>>nn>>mm&&(mm||nn))
	{
		k++;
        for(i=1;i<=nn;i++)
		{
			cin>>s>>r;
			a[i][0]=s-r;
			a[i][1]=s+r;
		}
		for(m=1;m<=mm;m++)
			for(n=m;n<=nn;n++)
			{
				if(m==n)
				{
					if(m==1)
					{
						p[n][m]=a[1][0];
						h[n][m]=a[1][1];
					}
					else
					{
						p[n][m]=a[n][0]+p[n-1][m-1];
						h[n][m]=a[n][1]+h[n-1][m-1];
					}
					b[n][m]=1;
				}
				else if(m==1)
				{
					if(abs(p[n-1][m])<abs(a[n][0])||(abs(p[n-1][m])==abs(a[n][0])&&h[n-1][m]>a[n][1]))
					{
						p[n][m]=p[n-1][m];
						h[n][m]=h[n-1][m];
						b[n][m]=0;
					}
					else
					{
						p[n][m]=a[n][0];
						h[n][m]=a[n][1];
						b[n][m]=1;
					}
				}
				else
				{
					i=abs(p[n-1][m-1]+a[n][0]);
					if(abs(p[n-1][m])<i||(abs(p[n-1][m])==i&&h[n-1][m]>h[n-1][m-1]+a[n][1]))
					{
						p[n][m]=p[n-1][m];
						h[n][m]=h[n-1][m];
						b[n][m]=0;
					}
					else
					{
                        p[n][m]=p[n-1][m-1]+a[n][0];
						h[n][m]=h[n-1][m-1]+a[n][1];
						b[n][m]=1;
					}
				}
			}
		cout<<"Jury #"<<k<<endl;
		cout<<"Best jury has value "<<(p[nn][mm]+h[nn][mm])/2<<" for prosecution and value "<<(-p[nn][mm]+h[nn][mm])/2<<" for defence:\n"; 
		show(nn,mm);
		cout<<"\n\n";
	}
}

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