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

求大牛指正错误

Posted by daweibayu at 2011-04-15 10:23:10 on Problem 3624
这是为什么?为什么数组开到3402就Runtime Error,而20000就可以?
还有为什么动态开辟数组就不对了,贴出代码,求大牛指正
#include <iostream>
using namespace std;
int main()
{
	int m,n,i,j;
	int a,b;
	int *q;
	scanf("%d%d",&n,&m);
	q=(int*)malloc(sizeof(int)*(n+1));
	memset(q,0,sizeof(q));
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&a,&b);
		for(j=m;j>=a;j--)
				if(q[j]<(q[j-a]+b))
					q[j]=q[j-a]+b;
	}
	printf("%d\n",q[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