fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner in = new Scanner(System.in);
  10. int n=in.nextInt();
  11. int m=in.nextInt();
  12. long[][] X = new long[100][100];
  13. String ans = new String("");
  14. for (int i=n-1; i>=0; i--){
  15. for (int j=0; j<m; j++)X[i][j]=in.nextLong();
  16. }
  17. for(int i=1;i<n;i++)X[i][0]=X[i][0]+X[i-1][0];
  18. for(int j=1;j<m;j++)X[0][j]=X[0][j]+X[0][j-1];
  19. for (int i=1; i<n; i++){
  20. for (int j=1; j<m; j++) X[i][j]=X[i][j]+Math.max(X[i - 1][j], X[i][j - 1]);
  21. }
  22. int k=n-1, t=m-1;
  23. while (k>0 || t>0){
  24. if (k>0 && t>0){
  25. if (X[k-1][t]>X[k][t-1]){
  26. ans+="F";
  27. k--;
  28. }
  29. else{
  30. ans+="R";
  31. t--;
  32. }
  33. }
  34. else if (k==0){
  35. ans+="R";
  36. t--;
  37. }
  38. else if (t==0){
  39. ans+="F";
  40. k--;
  41. }
  42. }
  43. String reverse = new StringBuffer(ans).reverse().toString();
  44. System.out.println(reverse);
  45. }
  46. }
Success #stdin #stdout 0.08s 29404KB
stdin
7 8
23 4 7 8 94 23 5 6
2 9 7 56 83 5 44 2
1 2 3 4 5 6 7 8
8 7 6 5 4 32 2 1
90 87 3 5 4 3 2 5
28 75 60 94 33 3 2 7
76 92000 402 28 3 2 11 200
stdout
RRFRFFFFRFRRR