fork download
  1. #include<stdio.h>
  2. #include<vector>
  3. using namespace std;
  4. #define ll long long
  5. const ll MAX=1LL<<60;
  6. int n;
  7. ll a[505][505];
  8. vector <int> b;
  9. int main()
  10. {
  11. //freopen("podm.in","r",stdin);
  12.  
  13. //freopen("podm.out","w",stdout);
  14.  
  15. scanf("%d",&n);
  16.  
  17. for(int i=0;i<=n;i++)
  18. {
  19. int x;
  20. scanf("%d",&x);
  21. b.push_back(x);
  22. }
  23.  
  24. for(int l=1;l<=n;l++)
  25. {
  26. for(int i=1;i+l<=n;i++)
  27. {
  28. int j=i+l;
  29. a[i][j]=MAX;
  30. for(int k=i;k<j;k++)
  31. {
  32. a[i][j]=min(a[i][k]+a[k+1][j]+(ll)b[i-1]*b[k]*b[j],a[i][j]);
  33. }
  34. }
  35. }
  36. printf("%Ld\n",a[1][n]);
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5408KB
stdin
4
13 5 89 3 34
stdout
2856