1 条题解
-
0
用 long long 计算非负整数三角形的最大路径和。
#include <bits/stdc++.h> using namespace std; int main(){int n;cin>>n;vector<long long>d(n+1,LLONG_MIN/4);d[0]=0;for(int i=1;i<=n;i++){vector<long long>a(i);for(auto&x:a)cin>>x;for(int j=i-1;j>=0;j--)d[j]=max(d[j],j?d[j-1]:LLONG_MIN/4)+a[j];}cout<<*max_element(d.begin(),d.end())<<"\n";}
- 1
信息
- ID
- 3963
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 4
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者