poj 1163 The Triangle

来源:互联网 发布:云计算行业怎么样 编辑:程序博客网 时间:2024/05/06 07:32
/*  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;}