Cent Savings (DP) 分类: ACM dp 2015-08-0
2015-12-31 08:40
281 查看
Cent Savings
Time Limit: 5000ms, Special Time Limit:12500ms, Memory Limit:65536KB
Total submit users: 59, Accepted users: 45
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.
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 1
13 21 55 60 42
5 2
1 1 1 1 1
Sample Output
190
0
Problem Source
NWERC 2014
n-1个空,然后插d块板
dp[i][j]表示前n前物品被分成j-1堆的最少花费
状态转移方程式:dp[i][j]=min(dp[i-1][j]+a[i],(dp[i-1][j-1]+5+a[i])/10*10);
版权声明:本文为博主原创文章,未经博主允许不得转载。
Time Limit: 5000ms, Special Time Limit:12500ms, Memory Limit:65536KB
Total submit users: 59, Accepted users: 45
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.
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 1
13 21 55 60 42
5 2
1 1 1 1 1
Sample Output
190
0
Problem Source
NWERC 2014
n-1个空,然后插d块板
dp[i][j]表示前n前物品被分成j-1堆的最少花费
状态转移方程式:dp[i][j]=min(dp[i-1][j]+a[i],(dp[i-1][j-1]+5+a[i])/10*10);
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #define maxn 2005 #define inf 0X3f3f3f3f using namespace std; long long dp[maxn][maxn]; int a[maxn]; long long lcl(long long x) { if(x%10>=5) x+=10; x-=x%10; return x; } int main() { int n,d; while(scanf("%d %d",&n,&d)!=EOF) { for(int i=1;i<=n;i++) scanf("%d",&a[i]); memset(dp,0,sizeof(dp)); for(int i=1;i<n;i++) { for(int j=0;j<=d;j++) { if(j==0) dp[i][j]+=dp[i-1][j]+a[i]; else dp[i][j]=min(dp[i-1][j]+a[i],(dp[i-1][j-1]+5+a[i])/10*10); } } __int64 ans=inf; for(int i=0;i<=d;i++) { ans=min(ans,(dp[n-1][i]+5+a )/10*10); } printf("%I64d\n",ans); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
相关文章推荐
- Judging Troubles (multiset查找) 分类: ACM STL
- Judging Troubles (multiset查找) 分类: ACM STL
- Joke with permutation 分类: ACM 2015-08-03 14:09 1
- HNU Knockout Racing 分类: ACM 2015-08-03 13:35 1人
- Crazy Search(POJ1200) 分类: poj 2015-07-25 10:15 6
- Delicious Apples(多校联合训练) 分类: ACM 多校 201
- 1080 两个数的平方和 分类: 51nod 2015-07-20 22:20 11人阅读
- 1066 Bash游戏 分类: 51nod 2015-07-20 22:15 5人阅读 评
- 1088 最长回文子串 分类: 51nod 2015-07-20 22:09 8人阅读 评
- 1083 矩阵取数问题 分类: 51nod 2015-07-20 22:05 9人阅读 评
- 1083 矩阵取数问题 分类: 51nod 2015-07-20 22:05 9人阅读 评
- 1009 数字1的数量 分类: 51nod 2015-07-20 21:44 3人阅读 评
- 51nod 1091 线段的重叠 分类: 51nod 2015-07-18 21:49 7人阅读
- LoadRunner常用函数
- Request.url用法
- center
- iOS 开发如何获取当前的应用版本号
- relative 和 absolute
- 自定义View的XML报错问题
- 猿题库 iOS 客户端架构设计-唐巧