http://acm.hdu.edu.cn/showproblem.php?pid=2084

 

#include "iostream"
#include "cstdio"
#include "algorithm"
using namespace std;
int m[101][101],dp[101][101];
void DP(int n)
{
    for(int i=0;i<n;i++)
        dp[n-1][i]=m[n-1][i];
    for(int i=n-2;i>=0;i--)
        for(int j=0;j<=i;j++)
            dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+m[i][j];
}
int main()
{
    int n,t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            for(int j=0;j<=i;j++)
            scanf("%d",&m[i][j]);
        DP(n);
        printf("%d\n",dp[0][0]);
    }
    return 0;
}

 

相关文章:

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