#include<bits/stdc++.h>
using namespace std;
const int MAXN=101;
int a[MAXN][MAXN],dp[MAXN][MAXN];
int main(){
int T;
cin>>T;
while(T--){
int n;
cin>>n;
fill(a[0], a[0] + 101 * 101, 0);
fill(dp[0], dp[0] + 101 * 101, 0);
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= i; ++j) {
cin >> a[i][j];
}
}
for (int i = n - 1; i >= 0; --i) {
for (int j = 0; j <= i; ++j) {
dp[i][j] = min(dp[i + 1][j], dp[i + 1][j + 1]) + a[i][j];
}
}
cout << dp[0][0] << endl;
}
return 0;
}
1111. 数塔
最新推荐文章于 2024-11-12 13:55:23 发布