HDU 2084数塔 dp

//记忆化搜索

//从最底层开始向上搜索,每次保存最大的值

#include<iostream>

#define MAX 101

using namespace std;



int a[MAX][MAX];



int main()

{

	int cases;

	int height;

	cin >> cases;



	int c[MAX];

	int b[MAX];

	while (cases--)

	{

		cin >> height;



		for (int i = 0; i < height; i++)

		{

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

				cin >> a[i][j];

		}



		for (int i = height - 1; i > 0; i--)

		{

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

				a[i-1][j] = max(a[i-1][j]+a[i][j], a[i-1][j]+a[i][j+1]);

		}



		cout << a[0][0] << endl;

	}

	return 0;

}

你可能感兴趣的:(HDU)