|  | 
|  | 
| back to board | I got WA , can you tell me why?????????? Can you give some test data? Posted by Seany  7 Aug 2003 19:17#include<iostream>#include<fstream>
 #include<string>
 #include<algorithm>
 using namespace std;
 
 //ifstream fin("a.in");
 #define INF 1000000001             //defines for INF
 
 long L1,L2,L3,C1,C2,C3,s,t;
 long dis[10000];
 long m[10000][10000];               //dis[i]: the distance from
 station 0 to station i;
 int n;                             //the number of the stations
 long Cost(int len)        //caculate the cost for a distance of len;
 {
 if(len>0 && len<=L1)
 return C1;
 else
 if(len<=L2)
 return C2;
 else
 if(len<=L3)
 return C3;
 return INF;
 }
 void Initial()
 {
 cin>>L1>>L2>>L3>>C1>>C2>>C3>>n>>s>>t;
 if(s>t)
 swap(s,t);
 dis[0]=0;
 for(int i=1;i<n;i++)
 {
 long temp;
 cin>>dis[i];
 temp=dis[i]-dis[i-1];
 m[i-1][i]=Cost(temp);
 if(m[i-1][i]==INF)
 {
 cout<<"Error!"<<endl;
 return;
 }
 }
 }
 void Proc()
 {
 for(int k=n-2;k>=1;k--)
 for(int i=0;i<k;i++)
 {
 int j=i+n-k;
 m[i][j]=Cost(dis[j]-dis[i]);
 for(int x=i+1;x<j;x++)
 if(m[i][x]+m[x][j]<m[i][j])
 m[i][j]=m[i][x]+m[x][j];
 }
 }
 int main(int argc, char* argv[])
 {
 Initial();
 Proc();
 cout<<m[s-1][t-1]<<endl;
 return 0;
 }
 | 
 | 
|