| ||||||||||
| 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 | |||||||||
总是runtime error,我所有情况都考虑了呀,酋长不是最高等级,可以防止循环交换,最高、最低差<=m,请高手指点一下#include <iostream>
#include <math.h>
using namespace std;
int a[150][240],b[240];
int p,i,j,m,n,maxr=0,q,maxmoney=0,temp;
int f(int k){
int i;
int max=a[1][1];
if(a[k][3]!=0){
if(b[k]==0){
if(a[k][0]==0){
a[k][0]=1;
int maxi=0;
for(i=4;i<=a[k][3]+3;i++){
temp=f(a[k][i]);
if(temp!=-1 && temp+a[k][i+a[k][3]]<max && q-a[a[k][i]][2]<=m && q-a[a[k][i]][2]>=0){
max=temp+a[k][i+a[k][3]];
maxi=i;
for(p=1;p<=n;p++) a[p][0]=0;
}
}
if(maxi!=0){
b[k]=max;
maxi=0;
return b[k];
}
else{
b[k]=a[k][1];
return b[k];
}
}
else
return -1;
}
else
return b[k];
}
else
return a[k][1];
}
int main(){
cin>>m;
cin>>n;
for (i=1;i<=n;i++){
cin>>a[i][1];
cin>>a[i][2];
if(maxr<a[i][2])
maxr=a[i][2];
cin>>a[i][3];
for (j=1;j<=a[i][3];j++){
cin>>a[i][j+3];
cin>>a[i][a[i][3]+3+j];
}
}
for (i=0;i<=239;i++) b[i]=0;
for (i=1;i<=n;i++) a[i][0]=0;
if (maxr-m>a[1][2]){
for (q=a[1][2]+m;q>=a[1][2];q--){
for (i=0;i<=239;i++) b[i]=0;
for (i=1;i<=n;i++) a[i][0]=0;
if(maxmoney<f(1))
maxmoney=f(1);
}
}
else{
for (q=maxr;q>=a[1][2];q--){
for (i=0;i<=239;i++) b[i]=0;
for (i=1;i<=n;i++) a[i][0]=0;
if(maxmoney<f(1))
maxmoney=f(1);
}
}
cout<<maxmoney;
return 0;
}
/*
1 3
10000 3 2
2 8000
3 7000
1000 2 1
3 600
1300 2 1
2 700
*/
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator