CDOJ 1114 Cent Savings
来源:互联网 发布:淘宝三星手机官网 编辑:程序博客网 时间:2024/06/05 07:13
Cent Savings
Time Limit: 6000/2000MS (Java/Others) Memory Limit: 262144/262144KB (Java/Others)
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, booking 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 for1≤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 and output
5 113 21 55 60 42
190
5 21 1 1 1 1
0
Source
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;#define INF 0x3f3f3f3fint dp[2010][25],p[2010],N,D;/*int min(int a,int b,int c){if(a>=b && a>=c) return a;if(b>=a && b>=c) return b;if(c>=a && c>=b) return c;}*/int main(){scanf("%d%d\n",&N,&D);memset(dp,0x3f,sizeof(dp));for(int i=1;i<=N;i++){scanf("%d",&p[i]);dp[i][0]=p[i];if(i>1) dp[i][0]+=dp[i-1][0];}for(int j=1;j<=D;j++)for(int i=1;i<=N;i++){if(dp[i-1][j-1]!=INF)dp[i][j]=min(((dp[i-1][j-1]+5)/10)*10+p[i],dp[i][j]);if(dp[i-1][j]!=INF)dp[i][j]=min(dp[i-1][j]+p[i],dp[i][j]);}/*for(int i=1;i<=N;i++){for(int j=0;j<=D;j++) printf("%d ",dp[i][j]);printf("\n");}*/int ans=0X3f3f3f3f;for(int i=0;i<=D;i++)ans=min(((dp[N][i]+5)/10)*10,ans);printf("%d\n",ans);}
- CDOJ 1114 Cent Savings
- Cent Savings (DP)
- UVALive6952 Cent Savings DP
- Cent Savings UVALive
- HNU Cent Savings (DP)
- uva 6952 Cent Savings dp
- Cent Savings (DP) 分类: ACM dp 2015-08-0
- Savings Account
- Daylight Savings Time (DST)
- HOJ 2597 Savings Account
- Hdu 2398 - Savings Account
- hdu2398 Savings Account - 数学
- TimeZone里的daylight savings
- TimeZone里的daylight savings
- cent os
- CDOJ Clock
- CDOJ Flagstone
- CDOJ 149
- acm算法之线段树
- hdu 1058 Humble Numbers
- 阿里云主机上部署dotproject
- 【三层】宏观总结
- 15第十一周项目二——职员有薪水了(2)
- CDOJ 1114 Cent Savings
- 容易想复杂的"回环变位"
- log4cplus 学习
- 51单片机 超声波测距组件
- 测试用例的编写
- hdu 1272 小希的迷宫 并查集
- Docker MAC脚本
- 字节流和字符流分别读取文件
- cocos2d::DrawPrimitives和DrawNode分别实现画板功能