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个板子后的最小值

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int a[];
ll dp[][];
ll cal(ll x)
{
if(x%>=)
x+=;
x-=x%;
return x;
}
int main()
{
int n,d;
scanf("%d%d",&n,&d);
for(int i=;i<=n;i++)
a[i]=read();
for(int i=;i<=n-;i++)
{
for(int j=;j<=d;j++)
{
if(j==)
dp[i][j]+=dp[i-][j]+a[i];
else
dp[i][j]=min(dp[i-][j]+a[i],cal(dp[i-][j-]+a[i]));
}
}
ll ans=inf;
for(int j=;j<=d;j++)
ans=min(cal(dp[n-][j]+a[n]),ans);
cout<<ans<<endl;
}

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. 【swupdate文档 五】从可信的来源更新镜像

    从可信的来源更新镜像 现在越来越重要的是,设备不仅要能安全地进行更新操作, 而且要能够验证发送的图像是否来自一个已知的源, 并且没有嵌入恶意软件. 为了实现这个目标,SWUpdate必须验证传入的镜像 ...

  2. 4B/5B编码原理

    4B/5B编码原理 什么是4B/5B编码? 4B/5B编码是百兆以太网(即快速以太网)中线路层编码类型之一,就是用5bit的二进制数来表示4bit二进制数,映射方式如下表所示: 为什么要进行4B/5B ...

  3. pip安装模块时:error: command 'gcc' failed with exit status 1

    用安装python模块出现error: command 'gcc' failed with exit status 1 问题: gcc编译缺少模块 解决方法: yum install gcc libf ...

  4. Nginx服务安全设置和参数调优

    1.添加参数隐藏Nginx版本号 vim /application/nginx/conf/nginx.conf #http标签下添加 server_tokens off; #测试 [root@cobb ...

  5. MySQL-事务特性

    1. 事务概念引入: 现实生活中,我们往往经常会进行转账操作,转账操作可以分为两部分来完成,转入和转出.只有这两部分都完成了才可以认为是转账成功.在数据库中,这个过程是使用两条语句来完成的,如果其中任 ...

  6. CentOS7.6使用flatpak安装软件

    1.安装flatpak(CentOS 7已默认安装Flatpak) yum -y install flatpak 2.添加Flathub仓库 flatpak remote-add --if-not-e ...

  7. 如何使用Inno Setup Compiler制作安装软件包

    工具/原料   Inno Setup Compiler汉化版软件 方法/步骤     启动Inno Setup Compiler汉化版软件.   选择创建新的空白脚本文件,按确定.   然后按下一步. ...

  8. Windows搭建python开发环境[一]

    首先需要去python的官网下载环境.鼠标移动到Downloads的tab上,在这里可以下载. python的环境还是很人性化的,没有那么多罗里吧嗦的配置什么的,下载好以后直接无脑next就行了,直到 ...

  9. centos7 lamp环境搭建

    一.安装Apache1.安装yum -y install httpd2.开启apache服务systemctl start httpd.service3.设置apache服务开机启动systemctl ...

  10. 【leetcode】 21. Merge Two Sorted Lists

    题目描述: Merge two sorted linked lists and return it as a new list. The new list should be made by spli ...