标签:
做水题的感觉真好。。。。
1: 1
2: 1 2
3: 1 2 3
4: 1 2 3 4
5: 1 2 3 4 5
dp[i][j]第i行第j个数取得的最大值
dp[i][j] = max(dp[i-1][j-1], dp[i-1][j]) + a[i][j]。
/********************************************************* Problem : 2084 ( 数塔 ) Judge Status : Accepted RunId : 14525016 Language : G++ Author : G_lory Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta **********************************************************/ #include <iostream> #include <cstdio> #include <algorithm> using namespace std; int a[105][105]; int dp[105][105]; int N; void solve() { for (int i = 1; i <= N; ++i) { for (int j = 1; j <= i; ++j) { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1]) + a[i][j]; } } int ans = dp[N][1]; for (int i = 2; i <= N; ++i) { ans = max(ans, dp[N][i]); } printf("%d\n", ans); } int main() { int t; scanf("%d", &t); while (t--) { scanf("%d", &N); for (int i = 1; i <= N; ++i) for (int j = 1; j <= i; ++j) scanf("%d",&a[i][j]); solve(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/wenruo/p/4732927.html