HDOJ 杭电2084
/* * Copyright (c) 2017, 安徽大学计算机科学与技术学院 * All rights reserved. * 作 者: 杨磊 * 完成日期:2017 年 01 月 12 日 * 思路:自底向上状态转移方程求解。 * 方程:s[i][j]+=max(s[i+1][j],s[i+1][j+1]); * 感言:人生的第一道DP题目 * 虽然是个水题却搞了2小时 * 继续加油 */ #include<cstdio> #include<iostream> #include<stdlib.h> #include<string.h> #include<algorithm> #include<cmath> #define maxn 105 int s[maxn][maxn]; using namespace std; int main(){ int t,N,i,j,sum=0,temp; cin>>t; while(t--){ cin>>N; for(i=1;i<=N;i++) for(j=1;j<=i;j++) cin>>s[i][j]; for(i=N-1;i>=1;i--){ for(j=1;j<=i;j++){ s[i][j]+=max(s[i+1][j],s[i+1][j+1]); } } cout<<s[1][1]<<endl; } return 0;}