-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMIXTURE.cpp
More file actions
49 lines (45 loc) · 799 Bytes
/
MIXTURE.cpp
File metadata and controls
49 lines (45 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[107];
ll dp[1002][1003];
ll sum(int i,int k)
{
ll ans=0;
for(int j = i;j<=k;j++)
{
ans+=a[j];
ans%=100;
}
return ans;
}
ll solve(int i,int j )
{
if(i>=j)
return 0;
if(dp[i][j]!=-1)
return dp[i][j];
dp[i][j] = 9999999;
for(int k = i ; k<=j; k++)
{
dp[i][j] = min(dp[i][j],solve(i,k)+solve(k+1,j)+sum(i,k)*sum(k+1,j));
}
return dp[i][j];
}
int main()
{
ll n;
while((scanf("%lld",&n))!=EOF)
{
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
dp[i][j]=-1;
}
}
cout<<solve(0,n-1)<<endl;
}
}