题目:
http://poj.org/problem?id=1651
#include <cstdio> #include <iostream> #define INF 0x3f3f3f3f using namespace std; int a[105]; int dp[105][105]; int main () { int n; while(scanf("%d", &n) != EOF) { for(int i=0; i<n; i++) { scanf("%d", &a[i]); } for(int step=0; step<n-2; step++) { for(int i=1; i+step<n-1; i++) { int j = i+step; dp[i][j] = INF; for(int k=i; k<=j; k++) { dp[i][j] = min(dp[i][j], dp[i][k-1]+dp[k+1][j]+a[i-1]*a[k]*a[j+1]); } } } printf("%d\n", dp[1][n-2]); } return 0; }