数字三角形问题(数塔问题)
-
Description
- 下图给出了一个数字三角形,请编写一个程序,计算从顶至底的某处的一条路径,使该路径所经过的数字和最大 Input
- 有很多个测试案例,对于每一个测试案例, 通过键盘逐行输入,第1行是输入整数(如果该整数是0,就表示结束,不需要再处理),表示三角形行数n,然后是n行数 Output
- 输出最大值
Example Input
5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
Example Output
30
代码块
#include<iostream>
#include<cmath>
#define MAX 1000
using namespace std;
int data[MAX][MAX]; //储存原始数据