首页 > 代码库 > 练习2014092101

练习2014092101

/********************************************************************* @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 solve(int i, int j);int main(int argc, const char* argv[]){    printf("%d\n", solve(0, 0));    return 0;}int solve(int i, int j){    return Data[i][j] + (i == NUM-1 ? 0 : std::max(solve(i+1, j), solve(i+1, j+1)));}

 

练习2014092101