题目链接:http://acm.hust.edu.cn/vjudge/contest/124435#problem/I
密码:acm
Sample Input 5 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 Sample Output 30
分析:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stack> 6 #include<math.h> 7 #include<queue> 8 #include<map> 9 using namespace std; 10 11 #define INF 0x3f3f3f3f 12 #define N 1534 13 14 int maps[N][N],dp[N][N]; 15 16 int main() 17 { 18 int n,i,j; 19 20 scanf("%d", &n); 21 22 for(i=1;i<=n;i++) 23 for(j=1;j<=i;j++) 24 scanf("%d", &maps[i][j]); 25 26 for(i=n;i>0;i--) 27 { 28 for(j=1;j<=i;j++) 29 dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+maps[i][j]; 30 } 31 32 printf("%d ", dp[1][1]); 33 34 return 0; 35 36 }