当前位置: 代码迷 >> 综合 >> HDU 2084 数塔 DP .
  详细解决方案

HDU 2084 数塔 DP .

热度:85   发布时间:2023-09-23 06:47:37.0

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2084

水..

#include<iostream>
#include<algorithm>
using namespace std;
typedef short int ST;
const int maxn=100+5;
ST n[maxn][maxn],d[maxn];
int main()
{ST T,N; cin>>T;while(T--){cin>>N;for(int i=0;i<N;i++)for(int j=0;j<=i;j++)cin>>n[i][j];	ST ans=0;for(int i=N-1;i>=0;i--)for(int j=0;j<=i;j++)if(i==N-1) d[j]=n[i][j];else d[j]=max(d[j],d[j+1])+n[i][j];cout<<d[0]<<endl;	}return 0;
}