Alananan @ 2024-07-31 14:24:06
#include<iostream>
#include<cstdio>
using namespace std;
const int N = 1010;
int n,f[N][N];
int main(){
scanf("%d",&n);
for(int i = 1;i <= n;i++){
for(int j = 1;j <= i;j++){
scanf("%d",&f[i][j]);
}
}
for(int i = 2;i <= n;i++){
for(int j = 1;j <= i;j++){
f[i][j] = max(f[i-1][j-1],f[i-1][j]);
}
}
int maxx = -1;
for(int i = 1;i <= n;i++){
if(f[N][i] > maxx){
maxx = f[N][i];
}
}
cout<<maxx<<endl;
return 0;
}
样例输出 1 怎么办啊QWQ
by hermione_wqx @ 2024-07-31 14:50:53
求关
#include<bits/stdc++.h>
using namespace std;
int a[1005][1005],dp[1005][1005];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++)cin>>a[i][j];
}
dp[1][1]=a[1][1];
for(int i=2;i<=n;i++){
for(int j=1;j<=i;j++){
dp[i][j]=max(dp[i-1][j],dp[i-1][j-1])+a[i][j];
}
}
int maxx=0;
for(int i=1;i<=n;i++){
if(dp[n][i]>=maxx)maxx=dp[n][i];
}
cout<<maxx;
return 0;
}