HDU

    import java.util.Scanner;
    
    
    public class Main {
    
        public static void main(String[] args) {
            
            Scanner scan = new Scanner(System.in);
            
            int c = scan.nextInt();
            
            for(int i = 0; i<c;i++){
            
                int n = scan.nextInt();
                
    //            System.out.println(n);
                
                int [][]dp = new int[n][n];
                
                
                
                for(int j = 0;j<n;j++){
    //                System.out.println();
                    for(int k = 0 ; k<=j;k++){
                        
                        dp[j][k]= scan.nextInt();
    //                    
    //                    System.out.print(dp[j][k]+" ");
                        
                    }
                    
                }
                
                for(int j = n-2 ;j>=0;j--){
                    for(int k = 0 ;k<=j;k++){
                        dp[j][k]+=Math.max(dp[j+1][k],dp[j+1][k+1]);
                    }
                }
                
                System.out.println(dp[0][0]);
                
                
                
                
                
            }
    
        }
    
    }

你可能感兴趣的:(HDU)