Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define int long long
- #define MAXI (1e17+10)
- #define N 5005
- // Driver code to test above functions
- int32_t main()
- {
- #ifndef ONLINE_JUDGE
- // for getting input from inpu.txt
- freopen("input.txt", "r", stdin);
- // for writing output to output.txt
- //freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(0);
- cin.tie(NULL);
- cout.tie(NULL);
- while(!cin.eof())
- {
- int n;
- cin >> n;
- int a[n+1], pre[n+1];
- int cost[n+1][n+1];
- memset(pre, 0, sizeof pre);
- for(int i=1;i<=n;i++)
- {
- cin >> a[i];
- pre[i] = pre[i-1] + a[i];
- }
- memset(cost, 0, sizeof cost);
- for(int len=2;len<=n;len++)
- {
- for(int i=1;i<=n-len+1;i++)
- {
- int j = i+len-1;
- cost[i][j] = MAXI;
- for(int k=i;k<=j-1;k++)
- {
- int x = (pre[k] - pre[i-1] + 100)%100;
- int y = (pre[j] - pre[k] + 100)%100;
- cost[i][j] = min(cost[i][j], cost[i][k] + cost[k+1][j] + x*y);
- }
- }
- }
- cout << cost[1][n] << endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment