标签:poj 1651 multiplication puzzl 区间dp 矩阵链乘
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6542 | Accepted: 3983 |
Description
Input
Output
Sample Input
6 10 1 50 50 20 5
Sample Output
3650
Source
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<string> #include<algorithm> #include<cstdlib> #include<set> #include<queue> #include<stack> #include<vector> #include<map> #define N 100010 #define Mod 10000007 #define lson l,mid,idx<<1 #define rson mid+1,r,idx<<1|1 #define lc idx<<1 #define rc idx<<1|1 const double EPS = 1e-11; const double PI = acos ( -1.0 ); const double E = 2.718281828; typedef long long ll; const ll INF = 1010010010100101001; using namespace std; ll dp[110][110]; ll a[110]; int n; int main() { while ( cin >> n ) { for ( int i = 1; i <= n; i++ ) scanf ( "%I64d", &a[i] ); memset ( dp, 0, sizeof dp ); for ( int l = 2; l < n; l++ ) { for ( int i = 1, j = i + l; j <= n; j++, i++ ) { dp[i][j] = INF; for ( int k = i + 1; k < j; k++ ) dp[i][j] = min ( dp[i][j], dp[i][k] + dp[k][j] + a[i] * a[j] * a[k] ); } } cout << dp[1][n] << endl; } return 0; }
POJ 1651 Multiplication Puzzle(区间dp)
标签:poj 1651 multiplication puzzl 区间dp 矩阵链乘
原文地址:http://blog.csdn.net/acm_baihuzi/article/details/41172431