Hnu Cent Savings (DP)

Source: Internet
Author: User

Cent Savings
Time limit: 5000ms, special time limit:12500ms,Memory Limit:65536KB
Total Submit users: 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 pro Blem set, inviting contestants, designing T-shirts, book-ing hotel rooms and so on. I am responsible for going shopping in the supermarket.

When I get to the cash register, I put all my n items on the conveyor belt and wait until all the other customers in the Q Ueue in front of me is served. While waiting, I realize it supermarket recently started to round the total price of a purchase to the nearest mult Iple of cents (with 5 cents being rounded upwards). For example, 94 cents is rounded to + cents, while the while is rounded to 100.

It's possible to divide my purchase into groups and to pay for the parts separately. I managed to find D dividers to divide my purchase on up to D + 1 groups. I wonder where to place the dividers to minimize and the total cost of my purchase. As I am running out of time, I don't want to rearrange items on the belt.


Input

The input consists of:

? One line with integers n (1≤n≤2000) and D (1≤d≤20), the number of items and the number of available dividers;

? One line with n integers p1,... pn (1≤pi≤10000 to 1≤i≤n), the prices of the items in cents. The prices is given in the same order as the items appear on the belt.


Output

Output the minimum amount of money needed to buy all the items with the using up to D dividers.


Sample Input
5 113 21 55 60 425 21 1 1 1 1
Sample Output
1900
#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--) {in            T 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]); } return0;} 


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hnu Cent Savings (DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.