1 5 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5
30
#include <iostream> #include <string> using namespace std; const int MAXX = 105; int tower[MAXX][MAXX]; int max(int x, int y){ if (x > y)return x; return y; } void solve(int n){ for (int i = n - 1; i >= 0; --i){ for (int j = 0; j <= i; ++j){ tower[i][j] += max(tower[i + 1][j], tower[i + 1][j + 1]); } } } int main(){ //freopen("in.txt", "r", stdin); int c, n; cin >> c; while (c--){ cin >> n; memset(tower, 0, sizeof(tower)); for (int i = 0; i < n; ++i){ for (int j = 0; j < n; ++j){ if (i >= j)cin >> tower[i][j]; } } solve(n); printf("%d\n",tower[0][0]); } }
HDU 2048 数塔(DP),布布扣,bubuko.com
原文地址:http://blog.csdn.net/iaccepted/article/details/29826917