http://acm.hit.edu.cn/hoj/problem/view?id=1058
简单的dp
/*This Code is Submitted by billforum for Problem 4000103 at 2012-02-01 18:08:39*/
#include <iostream>
using namespace std;
int d[1001][1001];
int max(int x,int y)
{
return (x>y?x:y);
}
int main(int args,char** argv)
{
int n;
int tmp1,ans,tmp2;
while(cin>>n)
{
ans=0;
for(int i=0;i<n;i++)
for(int j=0;j<=i;j++)
{
cin>>d[i][j];
}
for(int s=1;s<n;s++)
{
for(int t=0;t<=s;t++)
{
if(t>=1) tmp1=d[s-1][t-1];
else tmp1=0;
if(s-1>=t) tmp2=d[s-1][t];
else tmp2=0;
d[s][t]=d[s][t]+max(tmp2,tmp1);
}
}
for(int j=0;j<n;j++)
if(d[n-1][j]>ans) ans=d[n-1][j];
cout<<ans<<endl;
}
return 0;
}