/*
Name: poj 1163 The Triangle
Author: Unimen
Date: 06-05-11 23:20
Description: 动规基础题
*/
/*
解题报告:动规基础题
转移方程:dp[i][j] = max(dp[i+1][j], dp[i+1][j+1]) + a[i][j](指三角形中该点的值)
a[i][j] i==n
*/
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN = 102;
int array[MAXN][MAXN];
int result[MAXN][MAXN];
int main()
{
int n;
int i, j;
while(cin>>n)
{
memset(result, 0, sizeof(result));
//输入
for(i=1; i<=n; ++i)
{
for(j=1; j<=i; ++j)
{
cin>>array[i][j];
}
}
//处理
for(i=n; i>=1; --i)
{
for(j=1; j<=i; j++)
{
result[i][j] = max(result[i+1][j], result[i+1][j+1]) + array[i][j];
}
}
cout<<result[1][1]<<endl;
}
return 0;
}
poj 1163 The Triangle
最新推荐文章于 2020-06-28 17:35:24 发布