标签:
1 5 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5
30
#include<stdio.h> #include<string.h> #include<iostream> using namespace std; int d[101][101],a[101][101]; int t,n; int dfs(int i,int j){ if(d[i][j]>=0) return d[i][j]; //判断d[i][j]是否计算过 return d[i][j]=a[i][j]+(i==n-1?0:max(dfs(i+1,j),dfs(i+1,j+1))); } int main(){ scanf("%d",&t); while(t--){ memset(d,-1,sizeof(d)); scanf("%d",&n); for(int i=0;i<n;i++) for(int j=0;j<=i;j++) scanf("%d",&a[i][j]); printf("%d\n",dfs(0,0)); } return 0; }
标签:
原文地址:http://blog.csdn.net/z_huing/article/details/51344720