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 1029. Ministry

visitor Why always get crash at 6 [5] // Problem 1029. Ministry 28 Nov 2006 10:27
visitor Re: Why always get crash at 6 // Problem 1029. Ministry 28 Nov 2006 10:37
program ti1029;
var
  f:array[0..501,0..501]of integer;
  w,dp:array[0..501,0..501]of extended;
  i,j,k,n,m:integer;

procedure print(x,y:integer);
  begin
    if x<>1
      then begin
             if f[x,y]=y
               then print(x-1,y)
               else print(x,f[x,y]);
           end;
    writeln(y);
  end;

begin
  readln(m,n);
  for i:=1 to m do
   for j:=1 to n do
     read(w[i,j]);
  fillchar(dp,sizeof(dp),0);
  fillchar(f,sizeof(f),0);
  for i:=1 to n do
    dp[1][i]:=w[1][i];
  for i:=2 to m do
    begin
      for j:=1 to n do
        begin
          dp[i][j]:=dp[i-1][j]+w[i][j];
          f[i][j]:=j;
        end;
      for j:=2 to n do
        if dp[i][j-1]+w[i][j]<dp[i][j]
          then begin
                 dp[i][j]:=dp[i][j-1]+w[i][j];
                 f[i][j]:=j-1;
               end;
      for j:=n-1 downto 1 do
        if dp[i][j+1]+w[i][j]<dp[i][j]
          then begin
                 dp[i][j]:=dp[i][j+1]+w[i][j];
                 f[i][j]:=j+1;
               end;
    end;
  j:=1;
  for i:=1 to n do
    if dp[m][i]<dp[m][j]
      then j:=i;
  print(m,j);
end.
Quercitron Re: Why always get crash at 6 [3] // Problem 1029. Ministry 20 Sep 2008 15:40
try

5 6
525   0 171   0 872 673
  0 843   0   0   0   0
  0 277   0 202   0   0
  0   0 733 957  65  96
637 566   0   0   0 441

answer:
4 4 5 5 5 5
RASTA Re: Why always get crash at 6 // Problem 1029. Ministry 20 Mar 2009 11:13
some tests
input
3 4
0 0 0 0
0 0 0 0
0 0 0 0
output
1 1 1(or some like that)

input
3 4
1 0 0 0
1 0 0 0
0 1 1 2
output
2 2 1 1(or some like that)

Edited by author 20.03.2009 11:32
remdy21 Re: Why always get crash at 6 // Problem 1029. Ministry 3 Aug 2009 12:28
Is 4 4 5 5 5 5 4 3 correct?
Abdul Mumit Re: Why always get crash at 6 // Problem 1029. Ministry 23 Oct 2012 01:31
The fee is a "positive" integer not exceeding 10^9.