AETCH @ 2023-12-23 22:02:38
#include<bits/stdc++.h>
using namespace std;
int n,len,a[105][105],f[105][105],ans;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
cin>>a[i][j];
}
}
for(int i=n;i>=1;i--){
for(int j=i;j>=1;j--){
f[i][j]=a[i][j]+max(f[i+1][j],f[i+1][j+1]);
}
}
cout<<f[1][1];
return 0;
}
by AETCH @ 2023-12-23 22:04:36
#include<bits/stdc++.h>
using namespace std;
int n,len,a[1010][1010],f[1010][1010],ans;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
cin>>a[i][j];
}
}
for(int i=n;i>=1;i--){
for(int j=i;j>=1;j--){
f[i][j]=a[i][j]+max(f[i+1][j],f[i+1][j+1]);
}
}
cout<<f[1][1];
return 0;
}
AC了?
by rnf5114 @ 2023-12-23 22:08:19
@AETCH 1<=r<=1000
by AETCH @ 2023-12-23 22:12:21
谢谢