整数划分
够坑
记得开long long
优化:减少一维,将起点固定为1,枚举终点
f(i,j)=max(f(k,j-1)*num(k+1,i))
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn=1e6+5; 4 const int INF=1e9+7; 5 char s[105]; 6 int m; 7 long long dp[105][105],num[105][105]; 8 template <class t>void red(t &x) 9 { 10 x=0; 11 int w=1; 12 char ch=getchar(); 13 while(ch<'0'||ch>'9') 14 { 15 if(ch=='-') 16 w=-1; 17 ch=getchar(); 18 } 19 while(ch>='0'&&ch<='9') 20 { 21 x=(x<<3)+(x<<1)+ch-'0'; 22 ch=getchar(); 23 } 24 x*=w; 25 } 26 void input() 27 { 28 freopen("input.txt","r",stdin); 29 } 30 void read() 31 { 32 scanf("%s",s+1); 33 red(m); 34 } 35 void work() 36 { 37 int n=strlen(s+1); 38 for(int i=1;i<=n;++i) 39 { 40 for(int j=i;j<=n;++j) 41 for(int k=i;k<=j;++k) 42 num[i][j]=num[i][j]*10+s[k]-'0'; 43 dp[0][i]=num[1][i]; 44 } 45 for(int j=1;j<m;++j) 46 for(int i=1;i<=n;++i) 47 for(int k=1;k<=i;++k) 48 dp[j][i]=max(dp[j][i],dp[j-1][k]*num[k+1][i]); 49 printf("%lld",dp[m-1][n]); 50 } 51 int main() 52 { 53 input(); 54 read(); 55 work(); 56 return 0; 57 }