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

求救!!!为什么老是Memory Limit Exceed,N次了,请大侠帮忙

Posted by noskill at 2005-03-31 11:52:34 on Problem 1062
我是用链表做的,为什么还会Memory Limit Exceed?
#include<iostream.h>
#include<math.h>
struct snode{
  int change;
  int changevalue;
  snode *next;
};
struct listlk{
  snode *head;
};
listlk change[101];
int classn[101],value[101],gold[101],changenum[101],permit,peoplen;
void initlist(listlk &hl)
{hl.head=NULL;}
void firstinsertlist(listlk &hl,int item1,int item2)
{
  snode *newp=new snode;
  newp->change=item1;newp->changevalue=item2;
  newp->next=hl.head;
  hl.head=newp;
}
void clearlist(listlk &hl)
{snode *p=hl.head,*q;
  while(p!=NULL){
    q=p;
    p=p->next;
    delete q;
  }
  hl.head=NULL;
}

int countgold(int n)
{
  int i,temp; 
  snode *p=change[n].head; 
  while(p!=NULL)
  {
      if(classn[1]-classn[p->change]<=permit)
      {
        temp=p->changevalue+countgold(p->change);
        if(temp<value[n])value[n]=temp;
      }    
      p=p->next;
  }    
  return value[n];  
}    
int main()
{
  int i,j,temp1,temp2;
  cin>>permit>>peoplen;
  for(i=1;i<=peoplen;i++)
  {
      initlist(change[i]);
      cin>>gold[i]>>classn[i]>>changenum[i];
      for(j=1;j<=changenum[i];j++)
      {
          cin>>temp1>>temp2;
          firstinsertlist(change[i],temp1,temp2);
      }    
      value[i]=gold[i];
  }        
  cout<<countgold(1)<<endl;
  for(i=1;i<=peoplen;i++)clearlist(change[i]);
  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