fork(2) download
  1. uses math;
  2. var i,j,m,n:longint;
  3. w,a:array[0..100,0..100] of longint;
  4. s:string;
  5. begin
  6. readln(n,m);
  7. for i:=1 to n do
  8. for j:=1 to m do
  9. read(a[i,j]);
  10. for i:=1 to n do
  11. w[i,1]:=w[i-1,1]+a[i,1];
  12. for i:=1 to m do
  13. w[1,i]:=w[1,i-1]+a[1,i];
  14. for i:=1 to n do
  15. begin
  16. for j:=1 to m do
  17. begin
  18. if w[i,j]=0 then w[i,j]:=max(w[i-1,j],w[i,j-1])+ a[i,j];
  19.  
  20. end;
  21.  
  22. end; i:=n;j:=m;
  23. while (i>0)and(j>0) do
  24. begin
  25. // if i=1 then begin s:='R '+s; dec(j);end; if j=1 then begin s:='D '+s; dec(i); end;
  26. // if (i=0)or(j=0) then break;
  27. if(i=1)and(j=1) then break;
  28. if w[i-1,j]>w[i,j-1] then begin s:='D '+s;dec(i);end else
  29. begin dec(j); s:='R '+s;end;
  30. end;
  31. writeln(w[n,m]);
  32. writeln(s);
  33. end.
Success #stdin #stdout 0.01s 480KB
stdin
Standard input is empty
stdout
0