题目:求一个矩阵的任意两点所经过点的和的最大距离和路径。只能向右或者向下
第一种解法:求出最大距离或者最小距离和经过的路径。(利用动态规划)
import java.util.*;
public class Search_T
{
public static LinkedList<String> list = new LinkedList<String>();
public static void main(String[] args)
{
int[][] a = {
{1,2,9},
{4,5,9},
{7,8,9}};
System.out.println(search(a));
}
public static int search(int[][] a)
{
String[][] str = new String[a.length][a.length];
//String str=""+a[0][0];
int[][] k = new int[a.length][a.length];
for(int i=0;i<k.length;i++)
for(int j=0;j<k.length;j++)
{
if(i==0&&j==0)
{
k[i][j]=1;
str[i][j]=""+k[i][j];
continue;
}
if(i==0)
{
k[i][j]=a[i][j]+k[0][j-1];
str[i][j]=str[0][j-1]+"->"+a[i][j];
continue;
}
if(j=&