poj 1088 滑雪问题
import java.util.Scanner; public class Main{ static int a[][],r,c; public static void main(String [] args){ Scanner input=new Scanner(System.in); while(input.hasNext()){ r=input.nextInt(); c=input.nextInt(); a=new int[r][c]; int b[][]=new int[r][c]; int min=Integer.MIN_VALUE; for(int i=0;i<r;i++){ for(int j=0;j<c;j++){ a[i][j]=input.nextInt(); } } int sum=1; for(int i=0;i<r;i++){ for(int j=0;j<c;j++){ b[i][j]=sou(i,j,sum,b); if(b[i][j]>min) min=b[i][j]; } } System.out.println(min); } } private static int sou(int i, int j, int sum,int b[][]) { int e=1; if(j+1<c&&a[i][j]>a[i][j+1]){ if(b[i][j+1]>0){ //return sum+b[i][j+1]; int num=sum+b[i][j+1]; if(num>e) e=num; } else{ //return sum+sou(i,j+1,sum,b); int num=sum+sou(i,j+1,sum,b); if(num>e) e=num; } } if(i+1<r&&a[i][j]>a[i+1][j]){ if(b[i+1][j]>0){ //return sum+b[i+1][j]; int num=sum+b[i+1][j]; if(num>e) e=num; } else{ //return sum+sou(i+1,j,sum,b); int num=sum+sou(i+1,j,sum,b); if(num>e) e=num; } } if(j-1>=0&&a[i][j]>a[i][j-1]){ if(b[i][j-1]>0){ //return sum+b[i][j-1]; int num=sum+b[i][j-1]; if(num>e) e=num; } else{ //return sum+sou(i,j-1,sum,b); int num=sum+sou(i,j-1,sum,b); if(num>e) e=num; } } if(i-1>=0&&a[i][j]>a[i-1][j]){ if(b[i-1][j]>0){ //return sum+b[i-1][j]; int num=sum+b[i-1][j]; if(num>e) e=num; } else{ //return sum+sou(i-1,j,sum,b); int num=sum+sou(i-1,j,sum,b); if(num>e) e=num; } } return e; } }
补充:软件开发 , Java ,