Cent Savings

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=116998

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, 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 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

Sample Output

190

HINT

题意

这个商店交款方式是4舍5入的,然后你可以把你的商品分成d堆交钱

然后问你最少交多少钱

题解:

dp题呀

就相当于有n-1个空,插d个板子

那么我们就可以DP解决他,dp[i][j]表示前i个空插了j个板子后的最小值

代码:

  1. //qscqesze
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <ctime>
  6. #include <iostream>
  7. #include <algorithm>
  8. #include <set>
  9. #include <vector>
  10. #include <sstream>
  11. #include <queue>
  12. #include <typeinfo>
  13. #include <fstream>
  14. #include <map>
  15. #include <stack>
  16. typedef long long ll;
  17. using namespace std;
  18. //freopen("D.in","r",stdin);
  19. //freopen("D.out","w",stdout);
  20. #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
  21. #define maxn 200001
  22. #define mod 10007
  23. #define eps 1e-9
  24. int Num;
  25. char CH[];
  26. //const int inf=0x7fffffff; //нчоч╢С
  27. const int inf=0x3f3f3f3f;
  28. /*
  29.  
  30. inline void P(int x)
  31. {
  32. Num=0;if(!x){putchar('0');puts("");return;}
  33. while(x>0)CH[++Num]=x%10,x/=10;
  34. while(Num)putchar(CH[Num--]+48);
  35. puts("");
  36. }
  37. */
  38. inline ll read()
  39. {
  40. int x=,f=;char ch=getchar();
  41. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  42. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  43. return x*f;
  44. }
  45. inline void P(int x)
  46. {
  47. Num=;if(!x){putchar('');puts("");return;}
  48. while(x>)CH[++Num]=x%,x/=;
  49. while(Num)putchar(CH[Num--]+);
  50. puts("");
  51. }
  52. //**************************************************************************************
  53.  
  54. int a[];
  55. ll dp[][];
  56. ll cal(ll x)
  57. {
  58. if(x%>=)
  59. x+=;
  60. x-=x%;
  61. return x;
  62. }
  63. int main()
  64. {
  65. int n,d;
  66. scanf("%d%d",&n,&d);
  67. for(int i=;i<=n;i++)
  68. a[i]=read();
  69. for(int i=;i<=n-;i++)
  70. {
  71. for(int j=;j<=d;j++)
  72. {
  73. if(j==)
  74. dp[i][j]+=dp[i-][j]+a[i];
  75. else
  76. dp[i][j]=min(dp[i-][j]+a[i],cal(dp[i-][j-]+a[i]));
  77. }
  78. }
  79. ll ans=inf;
  80. for(int j=;j<=d;j++)
  81. ans=min(cal(dp[n-][j]+a[n]),ans);
  82. cout<<ans<<endl;
  83. }

uva 6952 Cent Savings dp的更多相关文章

  1. UVALive - 6952 Cent Savings dp

    题目链接: http://acm.hust.edu.cn/vjudge/problem/116998 Cent Savings Time Limit: 3000MS 问题描述 To host a re ...

  2. UVA.674 Coin Change (DP 完全背包)

    UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...

  3. uva 10817(数位dp)

    uva 10817(数位dp) 某校有m个教师和n个求职者,需讲授s个课程(1<=s<=8, 1<=m<=20, 1<=n<=100).已知每人的工资c(10000 ...

  4. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  5. UVA 562 Dividing coins(dp + 01背包)

    Dividing coins It's commonly known that the Dutch have invented copper-wire. Two Dutch men were figh ...

  6. uva 10453 - Make Palindrome(dp)

    题目链接:10453 - Make Palindrome 题目大意:给出一个字符串,通过插入字符使得原字符串变成一个回文串,要求插入的字符个数最小,并且输出最后生成的回文串. 解题思路:和uva 10 ...

  7. uva 10671 - Grid Speed(dp)

    题目链接:uva 10671 - Grid Speed 题目大意:给出N,表示在一个N*N的网格中,每段路长L,如今给出h,v的限制速度,以及起始位置sx,sy,终止位置ex,ey,时间范围st,et ...

  8. uva 1331 - Minimax Triangulation(dp)

    option=com_onlinejudge&Itemid=8&page=show_problem&category=514&problem=4077&mosm ...

  9. UVa 11825 - Hackers' Crackdown DP, 枚举子集substa = (substa - 1)&sta 难度: 2

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

随机推荐

  1. Git远程操作详解【转】

    转自:http://www.ruanyifeng.com/blog/2014/06/git_remote.html 作者: 阮一峰 日期: 2014年6月12日 Git是目前最流行的版本管理系统,学会 ...

  2. 记一个logrotate的配置文件权限问题

    问题描述 从git仓库更新了别人配置好的logrotate,发现不能正常运行.手工执行报错 error: Ignoring syslog because of bad file mode - must ...

  3. MySQL数据库设置为只读及测试【转】

    转自 mysql只读模式的设置方法与实验 - yumushui的专栏 - CSDN博客http://blog.csdn.net/yumushui/article/details/41645469 在M ...

  4. Tutorial 5: Relationships & Hyperlinked APIs

    转载自:http://www.django-rest-framework.org/tutorial/5-relationships-and-hyperlinked-apis/ Tutorial 5: ...

  5. 创建一个简单的Maven工程

    Maven的工程结构如下图所示: 大致来看,Maven的工程结构如下: 在创建maven工程时,可以通过骨架创建,也可以不通过骨架创建. 我们先用idea通过骨架创建一个Maven工程. 配置pom. ...

  6. .Net Core 部署到 CentOS7 64 位系统中的步骤

    建议使用 root 管理员账户操作 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是服务器一开机就启动服务器 上发 ...

  7. P3960 列队

    这是NOIP 2017最后一道题 不知道这道题有没有人代码写的和我一样麻烦. Solution 30分暴力 维护每行每列的元素. 每次删除一个元素的时候, 需要修改一行一列 因此复杂度上界\(O(nm ...

  8. 数据库介绍及MySQL安装

    阅读目录 一.数据库是什么? 二.数据库特点 三. 什么是数据库管理系统(DataBase Management System 简称DBMS) 四.数据库服务器.数据管理系统.数据库.表与记录的关系( ...

  9. Java门派的风险

    Java门派的风险 正在看周思博(www.joelonsoftware.com)的新文章.这次是疯狂攻击Java.主要论点是:Java不够难,作为工业语言不错,但作为学校的教学语言,就忒差了.学校应该 ...

  10. 【C#】IEnumrator的枚举数和IEnumerable接口

    声明IEnumerator的枚举数 要创建非泛型接口的枚举数,必须声明实现IEnumerator接口的类,IEnumerator接口有如下特性: 1.她是System.Collections命名空间的 ...