NYOJ_18_The Triangle
经典的数塔问题:
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<string> using namespace std; int dp[105][105]; int main() { int n,i,j; while(~scanf("%d",&n)) { memset(dp,0,sizeof(dp)); for(i=1;i<=n;++i) for(j=1;j<=i;++j) { scanf("%d",&dp[i][j]); dp[i][j]+=dp[i-1][j-1]>dp[i-1][j]?dp[i-1][j-1]:dp[i-1][j];//important } printf("%d\n",*max_element(dp[n],dp[n]+n)); } return 0; }