一定要初始化~
不开long long建祖宗~
#include<bits/stdc++.h>
using namespace std;
vector<int> f[101][101];
long long w[101];
vector<int> add(vector<int> a,vector<int>b){
vector<int> c;
int t=0;
for(int i=0;i<a.size()||i<b.size();i++){
if(i<a.size()) t+=a[i];
if(i<b.size()) t+=b[i];
c.push_back(t%10);
t/=10;
}
if(t>0) c.push_back(t);
return c;
}
vector<int> mul(vector<int> a,long long b){
vector<int> c;
long long t=0;
for(int i=0;i<a.size()||t;i++){
if(i<a.size()){
t+=a[i]*(long long)b;
}
//cout<<":"<<t<<endl;
c.push_back(t%10);
t/=10;
}
return c;
}
vector<int> min_v(vector<int> a,vector<int> b){
if(a.size()<b.size()){
return a;
}
if(a.size()>b.size()){
return b;
}
for(int i=a.size()-1;i>=0;i--){
if(a[i]>b[i]) return b;
else if(a[i]<b[i]) return a;
}
return a;
}
int main(){
//memset(f,0x3f,sizeof f);
int n;
cin>>n;
//vector<int> a = vector<int>(1,3);
//int b=5;
//vector<int> c = mul(a,b);
//for(int i=c.size()-1;i>=0;i--) cout<<c[i];
//cout<<endl;
for(int i=1;i<=n;i++){
cin>>w[i];
}
for(int len=3;len<=n;len++){
for(int l=1;l+len-1<=n;l++){
int r=l+len-1;
f[l][r]=vector<int>(55,1);
for(int k=l+1;k<=r-1;k++){
vector<int> t;
t.clear();
t.push_back(w[l]);
t=mul(t,w[k]);
t=mul(t,w[r]);
t=add(t,f[l][k]);
t=add(t,f[k][r]);
f[l][r]=min_v(f[l][r],t);
}
}
}
for(int i=f[1][n].size()-1;i>=0;i--)
cout<<f[1][n][i];
cout<<endl;
}
f[l][r]=vector[HTML_REMOVED](55,1);代表什么意思?
%%%
简洁易懂 楼主好棒