参考:https://blog.csdn.net/theonegis/article/details/45801201
https://blog.csdn.net/murmured/article/details/17484239
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 const int N=150; 6 int dp[N][N]; 7 int main() 8 { 9 int t; 10 while (cin>>t) 11 { 12 while (t--)//注意题目的输入顺序! 13 { 14 int n; 15 cin>>n; 16 for (int i=0;i<n;i++) 17 { 18 for (int j=0;j<=i;j++) 19 { 20 cin>>dp[i][j]; 21 } 22 } 23 for (int i=n-2;i>=0;i--) 24 { 25 for (int j=0;j<=i;j++) 26 { 27 dp[i][j]=dp[i][j]+max(dp[i+1][j],dp[i+1][j+1]); 28 } 29 } 30 cout<<dp[0][0]<<endl; 31 } 32 } 33 34 return 0; 35 }