-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathn.cpp
More file actions
48 lines (39 loc) · 673 Bytes
/
n.cpp
File metadata and controls
48 lines (39 loc) · 673 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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
ll int INF = 1e17;
int arr[405];
ll int dp[405][405];
ll int psum[405];
ll int kil(int s, int l)
{
if(s == l)
{
return 0;
}
if(dp[s][l] != -1)
return dp[s][l];
dp[s][l] = 1e15;
for(int i=s;i<l;i++)
{
dp[s][l] = min(dp[s][l], kil(s, i) + kil(i+1, l));
}
dp[s][l] += psum[l] - psum[s-1];
return dp[s][l];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(dp, -1, sizeof dp);
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>arr[i];
psum[i] = psum[i-1] + arr[i];
}
cout<<kil(1, n)<<endl;
return 0;
}