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

请大牛看看为什么会Runtime error?

Posted by jjxx at 2007-05-07 19:26:26 on Problem 1276
#include<iostream.h>
using namespace std;
#define MAX 12001
int f[MAX][MAX];

struct money
{
       int v,num;
}q[MAX];

int compare (const void *p, const void *q)
{
    return ((*(money*)q).v >(*(money*)p).v)? 1:-1;
}
int main()
{
    int n,m,temp;
    int i,j,k;
    
    while(scanf("%d",&m)!=EOF)
    {
       scanf("%d",&n);
       for(i=0;i<n;i++)
           scanf("%d%d",&q[i].num,&q[i].v);
       if(m==0 || n==0)
         printf("0\n");
       else
       { 
          qsort(q,m,sizeof(money),compare);
          for(i=0;i<=q[0].num;i++) f[0][i]=i*q[0].v;
          for(i=1;i<n;i++)
          {
             for(j=0;j<=q[i].num;j++)
             {
                f[i][j]=0;
                for(k=0;k<=q[i-1].num;k++)
                   if( f[i-1][k]+ j*q[i].v <= m && f[i-1][k]+j*q[i].v > f[i][j] ) f[i][j]=f[i-1][k]+j*q[i].v;
               //if(f[i][j]==0) break;
             }
          }
          temp=0;
          for(k=0;k<=q[n-1].num;k++)
            if(f[n-1][k]>temp) temp=f[n-1][k];
          printf("%d\n",temp);
       }
    }
    system("pause");
}

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