标签:style blog color io ar for 2014 div sp
/******************************************************************** * @file Main_practise.cpp * @date 2014-9-21 * @author Tiger * @brief 数字三角形 * @details 动态规划-递推计算 ********************************************************************/ #include <cstdio> #include <algorithm> const int NUM = 5; int Data[NUM][NUM] = { { 7 }, { 3, 8 }, { 8, 1, 0 }, { 2, 7, 4, 4 }, { 4, 5, 2, 6, 5 } }; int Sum[NUM][NUM]; int solve(int i, int j); int main(int argc, const char* argv[]) { for (int i=0; i<NUM; ++i) { for (int j=0; j<NUM; ++j) { Sum[i][j] = -1; } } printf("%d\n", solve(0, 0)); return 0; } int solve(int i, int j) { if (Sum[i][j] >= 0) { return Sum[i][j]; } else { return Sum[i][j] = Data[i][j] + (i == NUM-1 ? 0 : std::max(solve(i+1, j), solve(i+1, j+1))); } }
标签:style blog color io ar for 2014 div sp
原文地址:http://www.cnblogs.com/roronoa-zoro-zrh/p/3984511.html