#include<iostream> using namespace std; int d[100][100]; int *maxsum; //int n; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { cin >> d[i][j]; } } maxsum= d[n]; for (int i = n-1;i>=1;--i) { for(int j=1;j<=i;++j) { maxsum[j]=max(maxsum[j],maxsum[j+1])+d[i][j]; } } cout<<maxsum[1]<<endl; return 0; }
动态规划数字三角形
最新推荐文章于 2020-02-21 16:26:24 发布