hihoCoder#1037 数字三角形

原题地址

 

基本动归,题目中给的提示很有意思

 

代码:

 1 #include <iostream>

 2 

 3 using namespace std;

 4 

 5 #define SIZE 128

 6 

 7 int main() {

 8     int n;

 9     int puzzle[SIZE][SIZE];

10     

11     cin >> n;

12     for (int i = 0; i < n; i++)

13         for (int j = 0; j <= i; j++)

14             cin >> puzzle[i][j];

15     

16     for (int i = n - 2; i >= 0; i--)

17         for (int j = 0; j <= i; j++)

18             puzzle[i][j] += max(puzzle[i + 1][j], puzzle[i + 1][j + 1]);

19  

20  

21     cout << puzzle[0][0] << endl;

22     return 0;

23 }

 

你可能感兴趣的:(code)