forked from MoncefMhasni/AMPC-2015
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI.cpp
More file actions
33 lines (32 loc) · 753 Bytes
/
Copy pathI.cpp
File metadata and controls
33 lines (32 loc) · 753 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
#include<bits/stdc++.h>
#define INF 1+10000*2000
using namespace std;
int f(int n){
if(n%10>=5)return n+10-n%10;
else return n-n%10;
}
int main()
{
freopen("I.in","r",stdin);
freopen("I.out","w",stdout);
int n,d,sum[2001];
int tc;
cin>>tc;
while(tc--){
cin>>n>>d;
d++;
int tmp;
sum[0]=0;
for(int i=0;i<n;i++){
cin>>tmp;
sum[i+1]=sum[i]+tmp;
}
vector<vector<int> >dp(n+1,vector<int>(d+1, INF) );
dp[0][0]=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=d;j++)
for(int x=0;x<i;x++)
dp[i][j]=min(dp[i][j],dp[x][j-1]+f(sum[i]-sum[x]));
cout<<*min_element(dp[n].begin()+1,dp[n].end())<<endl;
}
}