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 answer

Posted by 574361905 at 2013-04-26 23:10:05 on Problem 3624
#include <stdio.h>
#define MAXN 4000 + 10
int W[MAXN],D[MAXN],d[MAXN][MAXN];

int main()
{
	int i,j,N,M;
	while (scanf("%d%d",&N,&M) == 2){
		for (i = 1; i <= N; i++) scanf("%d%d",&W[i],&D[i]);
		for (j = 0; j <= M; j++) d[0][j] = 0;
		for (i = 1; i <= N; i++)
			for (j = 0; j <= M; j++){
				d[i][j] = d[i-1][j];
				if (j >= W[i]) if (d[i][j] < d[i-1][j-W[i]] + D[i])
					d[i][j] = d[i-1][j-W[i]] + D[i];
			}
		printf("%d\n",d[N][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