HNU Cent Savings (DP)
来源:互联网 发布:移动的网络电视盒子 编辑:程序博客网 时间:2024/05/16 08:18
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.
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 queue in front of me are served. While waiting, I realize that this supermarket recently started to round the total price of a purchase to the nearest multiple of 10 cents (with 5 cents being rounded upwards). For example, 94 cents are rounded to 90 cents, while 95 are rounded to 100.
It is possible to divide my purchase into groups and to pay for the parts separately. I managed to find d dividers to divide my purchase in up to d + 1 groups. I wonder where to place the dividers to minimize the total cost of my purchase. As I am running out of time, I do not want to rearrange items on the belt.
Input
The input consists of:
• one line with two 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 for 1 ≤ i ≤ n), the prices of the items in cents. The prices are 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, using up to d dividers.
Sample Input
5 113 21 55 60 425 21 1 1 1 1Sample 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--) { 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;}
- HNU Cent Savings (DP)
- Cent Savings (DP)
- UVALive6952 Cent Savings DP
- uva 6952 Cent Savings dp
- Cent Savings (DP) 分类: ACM dp 2015-08-0
- CDOJ 1114 Cent Savings
- Cent Savings UVALive
- uvalive6952 - Cent Sa dp
- Savings Account
- HNU 12814 SIRO Challenge(最短路+状态压缩+dp)
- HNU Digit Sum (状态压缩)
- Hnu 11187 Emoticons :-) (ac自动机+贪心)
- Hnu 13190 Fractional Lotion(数论)
- HNU Joke with permutation (深搜dfs)
- 实体类-银行账户余额推算表(Savings Account Class)
- Daylight Savings Time (DST)
- HOJ 2597 Savings Account
- Hdu 2398 - Savings Account
- 单链表实例
- 设计模式3-代理模式
- 简单的深搜题
- 基本数据类型包装类
- c++ 11 基于范围的for循环
- HNU Cent Savings (DP)
- Business Rule Management With Drools
- java基础第七讲——集合、泛型、枚举、网络
- 显示时间的类
- POJ1664.放苹果
- Leetcode|Combination Sum II[递归回溯]
- 本博客已搬家至博客园:www.cnblogs.com/liuwu265
- 整点 appium 中部分 api 的使用方法
- Mybatis: $与#的区别