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

新手写C++,WA,求助

Posted by cz908640443 at 2012-10-06 11:39:05 on Problem 1717
#include<iostream>
using namespace std;
int x[1001],y[1001];
int f[1001][6001];
int main(){
	int i,j,m,n;
	m=0;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>x[i]>>y[i];
		m+=(x[i]+y[i]);
	}
	m=m/2;
	for(i=0;i<=m;i++){
		f[0][i]=9999;
	}
	f[0][0]=0;
	for(i=1;i<=n;i++){
		for(j=0;j<=m;j++){
			f[i][j]=9999;
		}
		for(j=x[i];j<=m;j++){
			f[i][j]=min(f[i][j],f[i-1][j-x[i]]);
		}
		for(j=y[i];j<=m;j++){
			f[i][j]=min(f[i][j],f[i-1][j-y[i]]+1);
		}
	}
	for(i=m;i>=1;i--){
		if(f[n][i]!=9999){
			cout<<f[n][i]<<endl;
			break;
		}
	}
	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