标签:区间 scan 矩阵乘法 algo bit 数据 fine turn ace
1 #include<bits/stdc++.h> 2 #include<iostream> 3 #include<cstring> 4 #include<cstdio> 5 #include<algorithm> 6 #include<vector> 7 #define ll __int64 8 #define PI acos(-1.0) 9 using namespace std; 10 int n; 11 ll a[1005]; 12 ll score[1005][1005]; 13 int main() 14 { 15 scanf("%d",&n); 16 for(int i=1; i<=n+1; i++) 17 scanf("%I64d",&a[i]); 18 memset(score,0,sizeof(score)); 19 for(int i=1; i<=n+1; i++) 20 for(int j=1; j<=n+1; j++) 21 score[i][j]=1000000000000000; 22 for(int i=1; i<=n; i++) 23 score[i][i+1]=0ll; 24 for(int i=n+1; i>=1; i--) 25 { 26 for(int j=i+1; j<=n+1; j++) 27 { 28 for(int k=i+1; k<j; k++) 29 score[i][j]=min(score[i][j],score[i][k]+score[k][j]+a[k]*a[i]*a[j]); 30 } 31 } 32 printf("%I64d\n",score[1][n+1]); 33 return 0; 34 }
标签:区间 scan 矩阵乘法 algo bit 数据 fine turn ace
原文地址:http://www.cnblogs.com/hsd-/p/6660042.html