Cent Savings |
Time Limit: 5000ms, Special Time Limit:12500ms, Memory Limit:65536KB |
Total submit users: 54, Accepted users: 36 |
Problem 13345 : No special judgement |
Problem description |
To host a regional contest like NWERC a lot of preparation is necessary: organizing rooms and computers, making a good problem set, inviting contestants, designing T-shirts, book- ing hotel rooms and so on. I am responsible for going shopping in the supermarket. |
Input |
The input consists of: |
Output |
Output the minimum amount of money needed to buy all the items, using up to d dividers. |
Sample Input |
5 1 13 21 55 60 42 5 2 1 1 1 1 1 |
Sample Output |
190 0 #include<stdio.h> #include<string.h> const int N = 2005; int main() { int dp[N][25],n,d,sum[N]; while(scanf("%d%d",&n,&d)>0) { for(int i=0; i<=n; i++) for(int j=1; j<=d; j++) dp[i][j]=1<<29; for(int j=0; j<=d; j++) dp[0][j]=0; sum[0]=0; for(int i=1; i<=n; i++){ scanf("%d",&sum[i]); sum[i]+=sum[i-1]; } for(int i=1; i<=n; i++) if(sum[i]%10>4) dp[i][0]=sum[i]-sum[i]%10+10; else dp[i][0]=sum[i]-sum[i]%10; for(int i=1; i<=n; i++) for(int j=1; j<=d; j++) for(int ti=i-1; ti>=0; ti--) { int ad=sum[i]-sum[ti]; if(ad%10>4){ ad=ad-ad%10+10; } else ad=ad-ad%10; if(dp[i][j]>dp[ti][j-1]+ad) dp[i][j]=dp[ti][j-1]+ad; } printf("%d\n",dp[n][d]); } return 0; } |
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/u010372095/article/details/47210551