cfm123456 @ 2024-03-17 10:21:30
dp做的,不知道错哪了
#include<bits/stdc++.h>
using namespace std;
const int N=1010;
int n,t;
int f[N][N];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
cin>>f[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
f[i][j]=max(f[i+1][j],f[i+1][j+1])+f[i][j];
}
}
cout<<f[1][1]*2<<endl;
return 0;
}
by C_Rong @ 2024-03-17 10:23:58
@cfm123456
#include<bits/stdc++.h>
using namespace std;
int a[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];
}
}
for(int i = n-1;i >= 1;i--){
for(int j = 1;j <= i;j++){
a[i][j] += max(a[i+1][j],a[i+1][j+1]);
}
}
cout << a[1][1];
return 0;
}
by cfm123456 @ 2024-03-17 10:28:06
谢谢大佬,已关