| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
DP过~~(矩阵乘法)#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define MX 20000000000000005
using namespace std;
long long dp[105][105];
int main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
long long n,i,j,k,s;
for(i=1;i<105;i++) for(j=1;j<105;j++) dp[i][j]=MX;
long long m[105];
cin>>n;
for(i=1;i<=n;i++) cin>>m[i];
for(i=1;i<=n;i++) dp[i][i]=0;
for(s=1;s<=n-1;s++){
for(i=1;i<=n-s;i++){
j=i+s;
for(k=i;k<j;k++){
dp[i][j]=min(dp[i][j],dp[k+1][j]+dp[i][k]+m[i-1]*m[k]*m[j]);
}
}
}
// for(i=1;i<=n;i++){
// for(j=1;j<=n;j++) cout<<dp[i][j]<<" ";
// cout<<endl;
// }
cout<<dp[2][n]<<endl;
return 0;
#ifdef home
eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
#endif
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator