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

Common Board

to Cristopher Moh, Help 1143 (+)
Posted by Miguel Angel 28 Jun 2002 10:04
Hi, i saw your comments, but i think that maybe i don't understand
well, cause i'm getting WA. My idea was the same as you, except the
way of keeping track of the movements. I save them as x[i][j],
where "i" and "j" are the points of the right and left of a starting
point "s", so "path starting at s" = min(c(s,r)+x[right(r)][l],c(s,l)
+x[r][left(l)]). Here's my method:
---------------------------------------------------------
double minPath(int r, int l, int dad)
{
 if (r==l)
 {
    if (m[r][l] < 0)
        m[r][l] = c(dad, r);
    return m[r][l];
 }
 if (m[r][l] < 0)
 {
    double right = c(dad, r) +minPath(prev(r), l, r);
    double left  = c(dad, l) +minPath(r, next(l), l);
    if (right < left) m[r][l] = right;
        else  m[r][l] = left;
 }
 return m[r][l];
}
--------------------------------------------------------
I try to do the your's, but get WA.
--------------------------------------------------------
 for (l=1; l<n-1; l++)
  for (s=0; s<n; s++)
  {
x[s][next(s,l)] = min( c(s,next(s,1)) + x[next(s,1)][next(s,l)],
             c(s,next(s,l)) + x[next(s,l)][next(s,1)]);
x[s][prev(s,l)] = min( c(s,prev(s,1)) + x[prev(s,1)][prev(s,l)],
             c(s,prev(s,l)) + x[prev(s,l)][prev(s,1)]);
  }
  MIN = 0.0;
  for (s=0; s<n-1; s++)
   MIN += c(s,s+1);
  for (s=0; s<n; s++)
  {
   if ( c(s,next(s,1)) + x[next(s,1)][prev(s,1)]<MIN )
    MIN = c(s,next(s,1)) + x[next(s,1)][prev(s,1)];
   if ( c(s,prev(s,1)) + x[prev(s,1)][next(s,1)]<MIN )
    MIN = c(s,prev(s,1)) + x[prev(s,1)][next(s,1)];
  }
I hope you can help me :).
email: miguelangelhdz@hotmail.com