一:题目
二:代码
#include <iostream>
#include<vector>
using namespace std;
int main()
{
int n;
int ans = 0;
cin >> n;
vector<vector<int> >v1(n+1,vector<int>(n+1,0));
vector<vector<int> >dp(n+1,vector<int>(n+1,0));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
cin >> v1[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
dp[i][j] = max(dp[i-1][j-1],dp[i-1][j]) + v1[i][j];
if(ans < dp[i][j]) ans = dp[i][j];
}
}
if(n%2 != 0) {
cout << dp[n][(n+1)/2];
} else {
int num1 = dp[n][(n+1)/2];
int num2 = dp[n][(n+1)/2+1];
cout << max(num1,num2);
}
return 0;
}
这个题是真的狗
|