题解
2025-07-31 19:27:21
发布于:北京
0阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define all0(x) (x).begin(),(x).end()
#define all1(x) (x).begin()+1,(x).end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long LL;
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const int N = 35 + 20;
const int INF = 0x3f3f3f3f;
const LL INFLL =0x3f3f3f3f3f3f3f3f;
int a[N][N] , b[N][N];
int dx[] = {-1 , -1};
int dy[] = {0 , -1};
void so() {
int n ;
cin >> n;
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= i ; j++ ){
cin >> b[i][j];
}
}
for(int i = 1; i <= n ;i++ ){
for(int j = 1 ; j <= i ; j++){
for(int k = 0 ; k < 2 ; k++){
int x = i + dx[k];
int y = j + dy[k];
a[i][j] = max(a[i][j] , a[x][y] + b[i][j]);
}
}
}
int ans = 0;
for(int i = 1; i <= n ; i++){
ans = max(ans , a[n][i]);
}
cout <<ans;
}
int main() {
IOS
int tt=1;
// cin >> tt;
while (tt--)
so();
}
这里空空如也
有帮助,赞一个