动态规划
![](http://img-my.csdn.net/uploads/201211/03/1351878068_8760.png)
![](http://img-my.csdn.net/uploads/201211/03/1351878135_7332.png)
// Name : 动态规划.cpp
// Author : mtt
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
int max(int a, int b) {
if (a >= b)
return a;
else
return b;
}
#include <iostream>
using namespace std;
int a[5][5] =
{ { 7 }, { 3, 8 }, { 8, 1, 0 }, { 2, 7, 4, 4 }, { 4, 5, 2, 6, 5 } };
int t[5][5];
int main() {
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
}
cout << endl;
}
int n = 4;
for (int i = n; i >= 0; i--) {
for (int j = n; j >= 0; j--) {
if (i == n) {
t[i][j] = a[i][j];
}
}
}
for (int i = n; i > 0; i--) {
for (int j = n; j > 0; j--) {
t[i - 1][j - 1] = max(t[i][j - 1], t[i][j]) + a[i - 1][j - 1];
}
}
cout << t[0][0] << endl;
return 0;
}