HDU 2084: 数塔(in Java)

数塔

 

 

import java.util.*;
class Main{
public static void main(String args[])
{
Scanner scanner=new Scanner(System.in);
int C=scanner.nextInt();
while(C--!=0)
{
int N=scanner.nextInt();
int [][]tower=new int[N][N];
for(int i=0;i<N;i++)
for(int j=0;j<=i;j++)
tower[i][j]=scanner.nextInt();
for(int i=N-2;i>=0;i--)
for(int j=0;j<=i;j++)
tower[i][j]+=Math.max(tower[i+1][j],tower[i+1][j+1]);
System.out.println(tower[0][0]);

}
}

转载于:https://www.cnblogs.com/zjnu/p/7352112.html

你可能感兴趣的:(HDU 2084: 数塔(in Java))