| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
求大牛指正错误这是为什么?为什么数组开到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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator