回忆童年
1 /* 2 ID: Starry21 3 LANG: C++ 4 TASK: ariprog 5 */ 6 #include<iostream> 7 #include<string> 8 #include<cstdio> 9 #include<cstring> 10 #include<vector> 11 #include<algorithm> 12 using namespace std; 13 #define N 1005 14 #define ll long long 15 #define INF 0x3f3f3f3f 16 int a[N][N],dp[N][N]; 17 int n; 18 int main() 19 { 20 //freopen("ariprog.in","r",stdin); 21 //freopen("ariprog.out","w",stdout); 22 scanf("%d",&n); 23 for(int i=1;i<=n;i++) 24 for(int j=1;j<=i;j++) 25 { 26 scanf("%d",&a[i][j]); 27 dp[i][j]=a[i][j]; 28 } 29 for(int i=n-1;i>=1;i--) 30 for(int j=1;j<=i;j++) 31 dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+a[i][j]; 32 printf("%d ",dp[1][1]); 33 return 0; 34 }