题意:商品总价按四舍五入计算,n个物品最多可分\(d+1\)段,求最小代价

\(dp[i][j]\):\(j\)个物品分\(i\)段

注意一个技巧是只在需要分出新的段时才四舍五入(旧段结算),这样就避免了不知道分段具体位置无法\(dp\)的情况

数据量比较小就不使用滚动数组了

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 1e5+11;
const int oo = 0x3f3f3f3f;
const double eps = 1e-7;
typedef long long ll;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
ll dp[22][maxn],p[maxn];
int n,d;
inline ll cal(ll x){
return (x+5)/10*10;
}
int main(){
while(cin>>n>>d){
memset(dp,0x3f,sizeof dp);
rep(i,1,n) p[i]=read();
dp[1][1]=p[1];
rep(i,2,n) dp[1][i]=dp[1][i-1]+p[i];
rep(i,2,d+1){
rep(j,i,n){
dp[i][j]=min(cal(dp[i-1][j-1])+p[j],dp[i][j-1]+p[j]);
}
}
ll ans=oo;
rep(i,1,d+1) ans=min(ans,cal(dp[i][n]));
println(ans);
}
return 0;
}

UVALive - 6952 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. Codeforces Round #207 (Div. 1) D - Bags and Coins 构造 + bitset优化dp + 分段查找优化空间

    D - Bags and Coins 思路:我们可以这样构造,最大的那个肯定是作为以一个树根,所以我们只要找到一个序列a1 + a2 + a3 .... + ak 并且ak为 所有点中最大的那个,那么 ...

  3. UVAlive 6131 dp+斜率优化

    这道题和06年论文<从一类单调性问题看算法的优化>第一道例题很相似. 题意:给出n个矿的重量和位置,这些矿石只能从上往下运送,现在要在这些地方建造m个heap,要使得,sigma距离*重量 ...

  4. UVALive 4764 dp

    DES: 这是一个新的游戏.给你一套牌.编号从1到100000.正常来说.你手中的牌和这次翻的牌是一样的,就会加一分.但是.如果是999的话.加三分.所以问你最大的分是多少. 貌似是简单的DP吧.(D ...

  5. UVALive - 4867 —— dp

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  6. UVALive 4731 dp+贪心

    这个题首先要利用题目的特性,先贪心,否则无法进行DP 因为求期望的话,越后面的乘的越大,所以为了得到最小值,应该把概率值降序排序,把大的数跟小的系数相乘 然后这种dp的特性就是转移的时候,由 i推到i ...

  7. hdu3480 Division(dp平行四边形优化)

    题意:将n个数分成m段,每段的代价为最大值减最小值的平方,为代价最小是多少n<=10000 ,m<=5000 题解:先拍好序,从小到大,这样绝对是花费最小的,不过怎么样来做呢?一定很容易想 ...

  8. POJ 3486 &amp; HDU 1913 Computers(dp)

    题目链接:PKU:HDU: PKU:http://poj.org/problem?id=3486 HDU:pid=1913" target="_blank">htt ...

  9. 大白第一章第四节dp例题

    入口 UVALive - 3882 #include<cstdio> using namespace std; ; int n,m,k,f[N]; int main(){ //f[i]表示 ...

随机推荐

  1. win10 Kinect2 Visualstudio2015 opencv3环境搭建

    1.下载kinect SDK ( Kinect for Windows SDK 2.0 ):  https://www.microsoft.com/en-us/download/details.asp ...

  2. 下载Redis

    1.下载当前Redis 官网:https://redis.io/ 当前稳定版本是4.0.11,如下图,点Download it下面的链接进行下载 2.下载历史版本的Resis 网址: http://d ...

  3. xgboost dmatrix中的 weight的重要性

    https://stackoverflow.com/questions/35983565/how-is-the-parameter-weight-dmatrix-used-in-the-gradien ...

  4. 数据结构 Merge合并排序

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. Part9---代码搬移不可少

    1.回顾ARM启动流程就可知道需要执行代码搬移 2.代码搬移 1)起点:NAND FLASH,今天的起点是SRAM垫脚石.为什么?因为我们要从nandflash取搬移数据需要先对其进行初始化,二而我们 ...

  6. Robot Framework - 基础关键字 BuiltIn 库(一)

    今天给大家分享的是Robot Framework 机器人框架中 BuiltIn 基础库的使用...BuiltIn 库里面提供了很多基础方法助力于我们在自动化测试领域中做的更好!——本系列教程是教会大家 ...

  7. ASP.NET MVC5 Authentication Filters执行链

    注意区分认证和授权: The following  are the differences in short: Authentication(认证): It is a process of verif ...

  8. 应用Bundle捆绑压缩技术

    从MVC4开始,我们就发现,项目中对Global.asax进行了优化,将原来在MVC3中使用的代码移到了[App_Start]文件夹下,而Global.asax只负责初始化.其中的BundleConf ...

  9. Entity Framework 6 初体验

    Entity Framework中有三种模式 Code First, Model First和Database First, Code First 是在EF4中新增的模式, 也跟NHibernate等 ...

  10. 如何让win32对话框居中显示

    在编写win32对话框程序,如果是用visual studio建的win32对话框程序,默认是不居中显示的,about 对话框也是这样的,用资源编辑器打开,可以在属性里面设置居中center 为tur ...