import java.util.Arrays;
public class Zahrada {
int[][] pocetJablk;
int[][] maxPocetJablk;
public Zahrada(int[][] pocetJablk){
this.pocetJablk=pocetJablk;
maxPocetJablk=new int[pocetJablk.length][pocetJablk[0].length];
}
public void vypocitaj(){
for (int i = 0; i < pocetJablk.length; i++) {
for (int j = 0; j < pocetJablk[0].length; j++) {
maxPocetJablk[i][j]=Math.max((i==0) ? 0 : maxPocetJablk[i-1][j],
(j==0) ? 0 : maxPocetJablk[i][j-1])
+ pocetJablk[i][j];
}
}
}
public void rekonstrukcia() {
char[] prechod = new char[pocetJablk.length + pocetJablk[0].length - 2];
int index = prechod.length - 1;
int i = pocetJablk.length - 1;
int j = pocetJablk[0].length - 1;
while (i != 0 || j != 0) {
if (maxPocetJablk[i][j] == ((i==0) ? 0 : maxPocetJablk[i-1][j]) + pocetJablk[i][j]) {
prechod[index] = 'D';
i = Math.max(0, i - 1);
} else {
prechod[index] = 'P';
j = Math.max(0, j - 1);
}
index--;
}
System.out.println(prechod);
}
public static void main(String[] args) {
int[][] pocetJablk= new int[][]{{10,5,100},{9,4,3},{1,8,2}};
Zahrada z= new Zahrada(pocetJablk);
z.vypocitaj();
for (int i = 0; i < z.maxPocetJablk.length; i++) {
System.out.println(Arrays.toString(z.maxPocetJablk[i]));
}
z.rekonstrukcia();
}
}