Guest User

MIXTURES

a guest
Apr 16th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. #define MAXI (1e17+10)
  5. #define N 5005
  6.  
  7.  
  8.  
  9. // Driver code to test above functions
  10. int32_t main()
  11. {
  12.  
  13. #ifndef ONLINE_JUDGE
  14. // for getting input from inpu.txt
  15. freopen("input.txt", "r", stdin);
  16. // for writing output to output.txt
  17. //freopen("output.txt", "w", stdout);
  18. #endif
  19.  
  20. ios_base::sync_with_stdio(0);
  21. cin.tie(NULL);
  22. cout.tie(NULL);
  23.  
  24.  
  25. while(!cin.eof())
  26. {
  27. int n;
  28. cin >> n;
  29.  
  30. int a[n+1], pre[n+1];
  31. int cost[n+1][n+1];
  32. memset(pre, 0, sizeof pre);
  33.  
  34. for(int i=1;i<=n;i++)
  35. {
  36. cin >> a[i];
  37. pre[i] = pre[i-1] + a[i];
  38. }
  39. memset(cost, 0, sizeof cost);
  40.  
  41. for(int len=2;len<=n;len++)
  42. {
  43. for(int i=1;i<=n-len+1;i++)
  44. {
  45. int j = i+len-1;
  46. cost[i][j] = MAXI;
  47. for(int k=i;k<=j-1;k++)
  48. {
  49. int x = (pre[k] - pre[i-1] + 100)%100;
  50. int y = (pre[j] - pre[k] + 100)%100;
  51.  
  52. cost[i][j] = min(cost[i][j], cost[i][k] + cost[k+1][j] + x*y);
  53. }
  54. }
  55. }
  56. cout << cost[1][n] << endl;
  57.  
  58. }
  59.  
  60.  
  61. return 0;
  62. }
Add Comment
Please, Sign In to add comment