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 |
Re:晕了,为什么相同代码提交一会runtimeerror一会memory limit exceed 代码如下.哪位兄弟指点指点In Reply To:晕了,为什么相同代码提交一会runtimeerror一会memory limit exceed 代码如下.哪位兄弟指点指点 Posted by:first at 2003-11-20 20:11:36 #include <iostream> #include <vector> using namespace std; int price[30]; short S[30]; short temps[30]; bool tie; short stamps[100][30]; int type,style,temptype,total,temptotal; void work(int); void trackback(int,short*); void print(int); void main() { int p; while(1) { cin>>p; type=0; while(p!=0) { type++; price[type]=p; cin>>p; } cin>>p; while(p!=0) { work(p); style=0; memset(S,0,30*sizeof(short)); memset(temps,0,30*sizeof(short)); total=0; style=0; temptotal=0; cin>>p; } } } void work(int p) { short i,j; for(i=0;i<=p;i++) for(j=1;j<=type;j++) stamps[i][j]=0; bool *yes=new bool[p+1]; memset(yes,0,(p+1)*sizeof(bool)); yes[0]=true; short *index=new short[p+1]; memset(index,0,(p+1)*sizeof(short)); for(i=1;i<=type;i++) for(j=0;j<=p;j++) if(yes[j]==true) if(j+price[i]<=p) { yes[j+price[i]]=true; stamps[j+price[i]][index[j+price[i]]]=i; index[j+price[i]]++; } if(yes[p]==false) cout<<p<<" --- none"<<endl; else { trackback(p,index); print(p); } delete []yes; delete []index; } void trackback(int p,short *index) { int i,high,temphigh,ttotal; short *S2=new short[30]; if(p) for(i=0;i<index[p];i++) { ttotal=temptotal; memcpy(S2,temps,30*sizeof(short)); temptotal++; temps[stamps[p][i]]++; trackback(p-price[stamps[p][i]],index); memcpy(temps,S2,30*sizeof(short)); temptotal=ttotal; } else { if(temptotal<5) { temptype=0; for(i=1;i<=type;i++) if(temps[i]>0) temptype++; if(temptype>style) { style=temptype; total=temptotal; memcpy(S,temps,30*sizeof(short)); tie=false; } else if(temptype==style) { if(temptotal<total) { total=temptotal; memcpy(S,temps,30*sizeof(short)); tie=false; } else if(temptotal==total) { high=0; for(i=0;i<=29;i++) if(S[i]>0) high=high>price[i]?high:price[i]; temphigh=0; for(i=0;i<=29;i++) if(temps[i]>0) temphigh=temphigh>price[i]?temphigh:price[i]; if(temphigh>high) memcpy(S,temps,30*sizeof(short)); else if(temphigh==high) { for(i=0;i<29;i++) if(S[i]!=temps[i]) break; if(i<29) tie=true; } } } } } delete []S2; } void print(int p) { int i,j; if(style==0) cout<<p<<" --- none"<<endl; else if(tie==true) cout<<p<<" ("<<style<<"): tie"<<endl; else { cout<<p<<" ("<<style<<"): "; for(i=1;i<type;i++) for(j=0;j<S[i];j++) cout<<price[i]<<" "; for(j=0;j<S[type]-1;j++) cout<<price[type]<<" "; cout<<price[type]<<endl; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator