class Main {
public static void main(String[] args) {
//JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。
int[][] coin ={
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0},
{0, 0, 1, 0, 1, 0, 0},
{0, 0, 0, 0, 1, 0, 1},
{0, 0, 0, 1, 0, 0, 1},
{0, 1, 0, 0, 0, 1, 0}
};
LinkedList<String>path = new LinkedList<String>();
System.out.println("收集到的硬币数:"+ collectCoin(coin, path));
printPath(path);
System.out.println("Hello world! - java.jsrun.net ");
}
public static int collectCoin(int coin[][],LinkedList<String> path) {
// 构建动态规划表格
int[][]dpArray = new int[coin.length][coin[0].length];
for (int i = 0; i < coin.length; ++i){
Arrays.fill(dpArray[i],o);
}
//填充动态规划表格
for (int i = 1; i < coin.length; ++i) {
for(int j = 1; j < coin[i].length; ++j) {
dpArray[i][j]= Math.max(dpArray[i-1][j],dpArray[i][j-1]) + coin[i][j];
}
}
//找到路径
int i = coin.length-1;
int j = coin[i].length - 1;
while(i >θ && j>θ) {
if (coin[i][j]> θ) {
path.addFirst("(" +i+","+ j+")");
}
if (dpArray[i-1][j]> dpArray[i][j-1]){
i=i- 1;
}
else {
j=j- 1;
}
}
return dpArray[coin.length-1][coin[0].length-1];
}
public static void printPath(LinkedList<String> path) {
for (int i = 0; i < path.size(); ++i) {
System.out.println(path.get(i));
}
}
}