1、HDU-2084   数塔

2、链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084   

3、总结:从下往上推,最后归于顶点。方程为  dp[i][j] = max(dp[i+1][j],dp[i+1][j+1])+a[i][j]  

#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<cstdio>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f

int main()
{
    int c,dp[110][110],a[110][110],n;
    scanf("%d",&c);
    while(c--)
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            for(int j=0;j<=i;j++)
        {
            scanf("%d",&a[i][j]);
        }

        for(int i=0;i<n+1;i++){
            dp[n][i]=0;
        }

        for(int i=n-1;i>=0;i--)
            for(int j=0;j<=i;j++)
        {
            dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+a[i][j];
        }
        printf("%d\n",dp[0][0]);

    }

    return 0;
}
View Code

相关文章:

  • 2021-06-22
  • 2021-06-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2021-08-27
  • 2021-11-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2021-06-10
  • 2021-09-14
  • 2021-11-28
  • 2021-04-19
相关资源
相似解决方案