ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1031. Railway Tickets

mcdoing_ron why WA #8??? help me [2] // Problem 1031. Railway Tickets 12 Sep 2010 14:55
I already change start and finish points
but still WA #8……
this is my coad
#include<iostream>
using namespace std;
const int maxn=10005;
long long f[maxn][maxn];
int cost[4];
int d[4];
int a[maxn];
int main()
{
            freopen("in.txt","r",stdin);
            for(int i=1;i<=3;i++)
                        cin>>d[i];
            for(int i=1;i<=3;i++)
                        cin>>cost[i];
            int n;
            cin>>n;
            for(int i=1;i<=n;i++)
                        for(int j=1;j<=n;j++)
                                    f[i][j]=INT_MAX;
            int s,e;
            cin>>s>>e;
            for(int i=2;i<=n;i++)
            {
                        cin>>a[i];
                        int temp=a[i]-a[i-1];
                        if(temp>d[2]) temp=cost[3];
                        else if(temp>d[1]) temp=cost[2];
                        else temp=cost[1];
                        f[i-1][i]=temp;
            }
            for(int i=1;i<=n;i++)
                        f[i][i]=0;
            for(int p=2;p<=n;p++)
                        for(int i=1;i<=n-p;i++)
                                    for(int j=i+1;j<=i+p;j++)
                                    {
                                                int k=1;
                                                while(1)
                                                {
                                                            if(j-k<=i) break;
                                                            if(a[j]-a[j-k]>d[3])break;
                                                            if(a[j]-a[j-k]>d[2])
                                                                        f[i][j]=min(f[i][j],f[i][j-k]+cost[3]);
                                                            else if(a[j]-a[j-k]>d[1])
                                                                        f[i][j]=min(f[i][j],f[i][j-k]+cost[2]);
                                                            else f[i][j]=min(f[i][j],f[i][j-k]+cost[1]);
                                                            k++;
                                                }
                                                k=1;
                                                while(1)
                                                {
                                                            if(i+k>=j) break;
                                                            if(a[i+k]-a[i]>d[3]) break;
                                                            if(a[i+k]-a[i]>d[2])
                                                                        f[i][j]=min(f[i][j],f[i+k][j]+cost[3]);
                                                            else if(a[i+k]-a[i]>d[1])
                                                                        f[i][j]=min(f[i][j],f[i+k][j]+cost[2]);
                                                            else f[i][j]=min(f[i][j],f[i+k][j]+cost[1]);
                                                            k++;
                                                }
                                    }
            int aaa=min(s,e);
            int bbb=max(e,s);
            cout<<f[aaa][bbb]<<endl;
            return 0;
}
cczzbb456 Re: why WA #8??? help me // Problem 1031. Railway Tickets 17 Nov 2010 18:13
i think you should solve it yourself..we got wronganswer because of bad thinking habit
Adhambek Re: why WA #8??? help me // Problem 1031. Railway Tickets 30 Oct 2014 08:36
try this test case:
1 2 3 1 2 3
2
2 1
1
ans = 1

Edited by author 30.10.2014 08:37