Pku 1163 the Triangle

 // triangle.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int depth = 0; cin >> depth; int **temp = new int*[depth]; for (int i = 0; i < depth; i ++) { temp[i] = new int[depth](); for (int j = 0; j <= i; j ++) { cin >> temp[i][j]; } } for (int i = depth - 2; i >= 0; i --) { for (int j = 0; j <= i; j ++) { temp[i][j] += max(temp[i + 1][j], temp[i + 1][j + 1]); } } cout << temp[0][0]; for (int i = 0; i < depth; i ++) delete [] temp[i]; delete [] temp; return 0; }

 

你可能感兴趣的:(动态规划,delete)