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 lccycc at 2009-08-16 09:07:50 on Problem 1015 and last updated at 2009-08-16 09:08:23
rt 我该考虑的都考虑了 
#include <iostream>
using namespace std;
const int maxn=610;
int f[220][41][maxn*2];//fg[i][maxn]---->fg[i][0];
int a[40],b[40];
int s[40];
int m,n;
int min(int a,int b){return a>b?b:a;}
int max(int a,int b){return a>b?a:b;}
int main()
{
	int i,j,k;
	int cass=0;
	while (cin>>n>>m,n)
	{
		cass++;
	
		for (i=0;i<220;i++) for (j=0;j<41;j++) for (k=0;k<maxn*2;k++) f[i][j][k]=-999999999;
		for (i=1;i<=n;i++) cin>>a[i]>>b[i];

		f[0][0][maxn]=0;
		for (i=1;i<=n;i++)
		{
			for (j=0;j<=m;j++)
				for (k=0;k<maxn*2;k++)
				{
					f[i][j][k]=max(f[i-1][j][k],f[i][j][k]);
					if (j>0&&k-a[i]+b[i]>=0&&k-a[i]+b[i]<maxn*2&&f[i-1][j-1][k-a[i]+b[i]]>=0)
						f[i][j][k]=max(f[i][j][k],f[i-1][j-1][k-a[i]+b[i]]+a[i]+b[i]);
				}
		}
		int t;
		for (t=0;t<maxn;t++) 
			if (f[n][m][t+maxn]>=0||f[n][m][-t+maxn]>=0)
			{
				if (f[n][m][t+maxn]<f[n][m][-t+maxn]) t=-t;
				break;
			}
		t+=maxn;
		int ss=0;
		for (i=n;i>0;i--)
			if (m-ss>0&&t-a[i]+b[i]>=0&&t-a[i]+b[i]<maxn*2&&f[i-1][m-ss-1][t-a[i]+b[i]]+a[i]+b[i]==f[i][m-ss][t])
			{
				s[ss++]=i;
				t-=a[i]-b[i];
			}
		j=k=0;
		for (i=0;i<m;i++) {j+=a[s[i]];k+=b[s[i]];}
		cout<<"Jury #"<<cass<<endl;
		cout<<"Best jury has value "<<j<<" for prosecution and value "<<k<<" for defence:"<<endl;
		for (i=m-1;i>=0;i--) cout<<' '<<s[i];cout<<endl<<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