From ffcc0ae0bc4ed4ba15d3510df3f5fee2fa653005 Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Sun, 1 May 2016 18:41:30 +0800 Subject: [PATCH] Create 1445.cpp --- QUSTOJ/1445.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 QUSTOJ/1445.cpp diff --git a/QUSTOJ/1445.cpp b/QUSTOJ/1445.cpp new file mode 100644 index 0000000..b30c96a --- /dev/null +++ b/QUSTOJ/1445.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +using namespace std; +int data[101][101]; +bool vis[101][101]; +int ans[101][101]; + +int d(int i,int j,int MaxDepth) +{ + if(i==MaxDepth) + { + return data[i][j]; + } + if(vis[i][j]) + { + return ans[i][j]; + } + int ret_a=d(i+1,j,MaxDepth); + int ret_b=d(i+1,j+1,MaxDepth); + int ret=(ret_a>ret_b)?(ret_a):(ret_b); + ret+=data[i][j]; + ans[i][j]=ret; + vis[i][j]=true; + return ret; +} +int main() +{ + int n; + scanf("%d",&n); + int t; + for(;n>0;n--) + { + scanf("%d",&t); + for(int i=1;i<=t;i++) + { + for(int j=1;j<=i;j++) + { + scanf("%d",&data[i][j]); + } + } + printf("%d\n",d(1,1,t)); + memset(vis,false,sizeof(bool)*101*101); + } + return 0; +}