forked from pranavanurag/SPOJSolutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMIXTURES.cpp
More file actions
60 lines (46 loc) · 789 Bytes
/
Copy pathMIXTURES.cpp
File metadata and controls
60 lines (46 loc) · 789 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
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
using namespace std;
int C[101], Memo[101][101], n;
void Refresh()
{
for (int i = 0; i <= 100; i++)
for (int j = 0; j <= 100; j++)
Memo[i][j] = -1;
}
int Smoke(int i, int k, int j)
{
int a = 0, b = 0;
for (int x = i; x <= k; x++)
a += C[x];
for (int x = k+1; x <= j; x++)
b += C[x];
a = a%100;
b = b%100;
return a*b;
}
int DP(int i, int j)
{
if (Memo[i][j] >= 0)
return Memo[i][j];
if (j == i)
Memo[i][j] = 0;
else
{
Memo[i][j] = 1000001;
for (int k = i; k <= j-1; k++)
Memo[i][j] = min(Memo[i][j], DP(i, k) + DP(k+1, j) + Smoke(i, k, j));
}
return Memo[i][j];
}
int main()
{
ios::sync_with_stdio(false);
while (cin>>n)
{
Refresh();
for (int i = 1; i <= n; i++)
cin>>C[i];
cout<<DP(1, n)<<endl;
}
return 0;
}