标签: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 main(int argc, const char* argv[]) { int Sum[NUM][NUM] = {0}; for (int i=0; i<NUM; ++i) { Sum[NUM-1][i] = Data[NUM-1][i]; } for (int i=NUM-2; i>=0; --i) { for (int j=0; j<=i; ++j) { Sum[i][j] = Data[i][j] + std::max(Sum[i+1][j], Sum[i+1][j+1]); } } printf("%d\n", Sum[0][0]); return 0; }
标签:style blog color io ar for 2014 div sp
原文地址:http://www.cnblogs.com/roronoa-zoro-zrh/p/3984505.html