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

有了滚动数组空间就没什么问题,但不知道为什么一直wrong,很惨、、、最后终于发现最大值比题意给的少了!白痴一只- -!

Posted by SWUST_smiles at 2010-08-15 22:02:41 on Problem 3624
#include <stdio.h>

int a[3][13000]={0};//先前13000一直写成12800了!竟然一直没发现!

int main()
{
int n,m,v[13000],w[13000],i,j;
while(scanf("%d%d",&n,&m)!=EOF){
for(i=1;i<=n;i++)
	scanf("%d%d",&w[i],&v[i]);
for(i=1;i<=n;i++)
	for(j=1;j<=m;j++)
		{
		if(w[i]>j) a[i%2][j]=a[(i-1)%2][j];
		else if(a[(i-1)%2][j-w[i]]+v[i]>a[(i-1)%2][j]) a[i%2][j]=a[(i-1)%2][j-w[i]]+v[i];
		else a[i%2][j]=a[(i-1)%2][j];
		}
printf("%d\n",a[n%2][m]);
}
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