7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program that calc

来源:互联网 发布:mac grapher 编辑:程序博客网 时间:2024/06/17 03:23
01.#include<cstdio>
02.#include<cstring>
03.#include<algorithm>
04.using namespace std;
05.int dp[110][110],num[110][110];
06.int main()
07.{
08.int n;
09.while(~scanf("%d",&n))
10.{
11.memset(dp,0,sizeof(dp));
12.for(int i=1;i<=n;i++)
13.for(int j=1;j<=i;j++)
14.scanf("%d",&num[i][j]);
15.for(int i=n;i>=1;i--)
16.for(int j=1;j<=i;j++)
17.{
18.dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+num[i][j];
19.}
20.printf("%d\n",dp[1][1]);
21.}
22.return 0;
23.}
阅读全文
0 0