POJ1651 Multiplication Puzzle(相邻乘积之和最小,区间DP)
http://blog.csdn.net/libin56842/article/details/9747021
http://www.cnblogs.com/devil-91/archive/2012/06/26/2562976.html
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <cctype> #include <vector> #include <iterator> #include <set> #include <map> #include <sstream> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define pb push_back #define debug printf("!\n") #define INF 10000 #define MAX(a,b) a>b?a:b #define blank pf("\n") #define LL long long #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) #define pqueue priority_queue const int MAXN = 1000 + 5; int n,m; int dp[110][110]; int a[110]; int main() { int i,j; while(sf("%d",&n)==1) { mem(dp,0); for(i =0;i<n;i++) sf("%d",&a[i]); for(int l = 2;l<n;l++) { for(i=0;i<n-l;i++) { j = i+l; dp[i][j] = 1<<30; for(int k =i+1;k<j;k++) { dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]+a[k]*a[i]*a[j]); } } } pf("%d\n",dp[0][n-1]); } return 0; }