poj 1163 The Triangle

#include<iostream>
using namespace std;
int n,triangle[101][101],tmp[101][101];

int highest(int ii,int jj)
{
if(ii==n)
return triangle[ii][jj];
if(tmp[ii][jj]!=-1)
return tmp[ii][jj];
int a,b;
a
=(triangle[ii][jj]+highest(ii+1,jj));
b
=(triangle[ii][jj]+highest(ii+1,jj+1));
tmp[ii][jj]
=a>b?a:b;
return tmp[ii][jj];
}
int main()
{
memset(tmp,
-1,sizeof(tmp));
cin
>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=i;j++)
cin
>>triangle[i][j];
cout
<<highest(1,1)<<endl;
return 0;
}

  

posted on 2011-07-17 23:52  sysu_mjc  阅读(116)  评论(0编辑  收藏  举报

导航