Codeforces 38 E. Let's Go Rolling!

保姆级教程:用C#和WinForms给MES系统上传数据,从界面设计到异常处理全流程 本文详细介绍了如何使用C#和WinForms为MES系统构建工业级数据上传应用,涵盖从界面设计到异常处理的全流程。通过实战案例和代码示例,帮助开发者快速掌握上位机系统与MES系统的数据对接技术,提升制造业数字化转型效率。 阅读详情
E. Let's Go Rolling!
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material point. You can stick pins in some of them and the cost of sticking in the marble number i is equal to ci, number ci may be negative. After you choose and stick the pins you need, the marbles will start to roll left according to the rule: if a marble has a pin stuck in it, then the marble doesn't move, otherwise the marble rolls all the way up to the next marble which has a pin stuck in it and stops moving there. If there is no pinned marble on the left to the given unpinned one, it is concluded that the marble rolls to the left to infinity and you will pay an infinitely large fine for it. If no marble rolled infinitely to the left, then the fine will consist of two summands:

  • the sum of the costs of stuck pins;
  • the sum of the lengths of the paths of each of the marbles, that is the sum of absolute values of differences between their initial and final positions.

Your task is to choose and pin some marbles in the way that will make the fine for you to pay as little as possible.

Input

The first input line contains an integer n (1 ≤ n ≤ 3000) which is the number of marbles. The next n lines contain the descriptions of the marbles in pairs of integers xi, ci ( - 109 ≤ xi, ci ≤ 109). The numbers are space-separated. Each description is given on a separate line. No two marbles have identical initial positions.

Output

Output the single number — the least fine you will have to pay.

题解:
dp1[i]表示前i个球的最小花费,dp2[i]表示固定第i个球的最小花费。
则dp2[i]=dp1[i-1]+cost[i]。
dp1[i]=dp2[j]+ans;
ans表示j~i之间的球滚到了j位置的花费

代码:

#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long 
struct node
{
	ll id,cost;
}c[3003];
bool cmp(node a,node b)
{
	return a.id<b.id;
}
ll dp1[3003],dp2[3003];
ll min1(ll a,ll b)
{
	if(a>b)return b;
	return a;
}
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld",&c[i].id,&c[i].cost);
	sort(c+1,c+n+1,cmp);
	dp1[1]=dp2[1]=c[1].cost;
	for(ll i=2;i<=n;i++)
	{
		ll ans=0;
		dp1[i]=dp2[i]=dp1[i-1]+c[i].cost;
		for(ll j=i-1;j>=1;j--)
		{
			ans=ans+(c[j+1].id-c[j].id)*(i-j);
			dp1[i]=min1(dp1[i],dp2[j]+ans);
		}
	}
	printf("%lld\n",dp1[n]);
	return 0;
}

FPGA系统性学习笔记连载_Day4 Xilinx ZYNQ7000系列 PS、PL、AXI 、启动流程基本概念篇 Zynq 就是两大功能块,PS 部分和 PL 部分, 说白了,就是 ARM 的 SOC 部分,和 FPGA部分。其中,PS 集成了两个 ARM Cortex™-A9 处理器,AMBA®互连,内部存储器,外部储器接口和外设。这些外设主要包括 USB 总线接口,以太网接口,SD/SDIO 接口,I2C 总线接口,CAN 总线接口,UART 接口,GPIO 等。 三、PS 和 PL 互联技术 3.1、ZYNQ 作为首款将高性能 ARM Cortex-A9 系列处理器与高性能 FPGA 在单芯片内紧密结合的产品, 阅读详情

相关推荐

【SoloPi】SoloPi使用2-功能使用,录制回放

Soloπ是什么 Soloπ是一个无线化、非侵入式的Android自动化工具,公测版拥有录制回放、性能测试、一机多控三项主要功能,能为测试开发人员节省宝贵时间。 录制回放功能 Soloπ拥有录制操作的能力,用户只需要通过Soloπ执行用例步骤,Soloπ就能够将用户的操作记录下来,并且支持在各个设备上进行回放,这一切都能够在手机上独立完成。 ...

q_Catherine的博客 5834

CodeForces 38 E.Let's Go Rolling!(dp)

Description 数轴上有nnn个质点,第iii个质点的坐标为xixix_i,花费为cicic_i,现在要选择其中一些点固定,代价为这些点的花费,固定的点不动,不固定的点会向左移动直至遇到固定的点,代价是这两点的距离,如果左边没有固定的点则花费为正无穷,问最小代价 Input 第一行一整数nnn表示点数,之后nnn行每行输入两个整数xi,cixi,cix_i,c_i表示第iii个点的坐...

ZSQ 508

[cryoEM] cryoSPARC简介

cryoSPARC系统结构概述 cryoSPARC是一个后端和前端高性能计算软件系统,为单颗粒冷冻电镜提供数据处理和图像分析能力,以及丰富的基于浏览器的用户截面和命令行工具。 Master-worker模式 系统基于主用户模式。 主进程(web应用,核心应用程序和MongoDB数据库)一起在主节点上运行。主节点需要相对轻量级的资源(2+ CPU< 16GB+ RAM)。 工作程序进程可以在具有GPU的任何可用节点上生成,负责所有实际计算和数据处理,并由主节点调度。注意:同一节点可以同时充当主节点和辅

进阶中的程序员吃吃的博客 7811

E. Let's Go Rolling!

http://codeforces.com/problemset/problem/38/E DP状态很容易想到,以后超long long 最大值的设定最好计算出一个边界, int_max的边界赋值 错误,导致WA那么多次。 View Code #include <iostream> #include <cstdio> #include <vector&...

weixin_30243533的博客 176

(OpenCV)图像目标尺寸检测

  本文翻译自pyimagesearch技术博客上的一篇文章,《Measuring size of objects in an image with OpenCV》,原文作者:Adrian Rosebrock 。 https://www.pyimagesearch.com/2016/03/28/measuring-size-of-objects-in-an-image-with-opencv...

明柳梦少的博客 7万+

完整内、外期货量化交易系统源码可售

支持客户登录校验,支持所有的实时行情和汇总报价功能、实时资讯(报价,列表,分时,分钟成交明晰,),多线程支持盘后收盘作业下载(日线,5分钟线,15分钟, 30分钟,60分钟线,),支持从服务器下载相关运行配置(来自服务器动态配置信息,如收盘日期等),实现状态条显示。收盘作业包括日线、5分钟线、15分钟线、30分钟、60分钟线、2小时线、4小时线每日分时走势。综合信息栏显示用户账户信息、合约信息、当日委托单记录、当日成交记录、当日平仓记录、当日跟单记录、当日(月/周)排行榜、下单栏、持仓信息;

qq_35600909的博客 1810

Codeforces Problem - 38E - Let's Go Rolling!(DP)

&#13; E. Let's Go Rolling!&#13; &#13; time limit per test&#13; 2 seconds&#13; &#13; memory limit per test&#13; 256 megabytes&#13; &#13; input&#13; standard input&#13; &#13; output&#13; standar...

蔡军帅 359

C++11并发与多线程笔记(2) 线程启动、结束,创建线程多法、join,detach

第二节 线程启动、结束,创建线程多法、join,detach 一、范例演示线程运行的开始 程序运行起来,生成一个进程,该进程所属的主线程开始自动运行;当主线程从main()函数返回,则整个进程执行完毕 主线程从main()开始执行,那么我们自己创建的线程,也需要从一个函数开始运行(初始函数),一旦这个函数运行完毕,线程也结束运行 整个进程是否执行完毕的标志是:主线程是否执行完,如果主线程执行完毕了,就代表整个进程执行完毕了,此时如果其他子线程还没有执行完,也会被强行终止【此条有例外,以后会解释】 创建

qq_38231713的博客 1万+

Codeforces E. Let's Go Rolling!

先把球按照坐标排序。 dp[i][j]考虑前i个qiu

fwm94的专栏 551

unity制作交互视频/互动视频

unity制作交互视频/互动视频 思路 1.先让unity播放视频 2. 视频播放结束后,视频暂停,按钮出现 3.按钮跳转下一个视频 视频播放 先创建UI-Raw Iamge 在Raw Iamge 挂载组件 Video Player 接着挂载视频播放的脚本 using UnityEngine; using UnityEngine.UI; using UnityEngine.Video; publi...

weixin_45588911的博客 8440

《RT-Thread入门与实战》第1章:RT-Thread概述与核心优势

2006年由熊谱翔发起2017年成立上海睿赛德电子科技公司2021年成为国内首个通过ISO 26262 ASIL-D认证的RTOS。

2301_79143213的博客 990

Let's Go Rolling! CodeForces - 38E

http://codeforces.com/problemset/problem/38/E数轴上有一些点,开始会向左边滚动,最终花费等于每个点滚过的距离,每个点还可以花费相应的数值来插上一个挡板,后面的点滚到该点则会停下,求最终的最小花费。dp。先按位置前后排序dp[i][j]代表第i个点在第j个点停下了,当然有j&lt;=i;对于当前这个点,如果在自己这个点停下,则去前面的点在前一个点停下和在自...

三水的鱼塘♂ 333

基于V7-690T FPGA纯逻辑实现NVMe SSD盘的读写(不使用软核)

a.NVMe的Admin CQ与Admin SQ命令放在Host内存中;因此SQ的64B要用FPGA的DDR或开一个bram空间存放,同理NVME写到HOST的CQ命令也需要存放在FPGA的DDR或一个bram空间,host收到NVME传来的MSI/MSI-X中断后,去CQ存放空间取CQ指令;b. 发送identify命令后,需要发送tial doorbell通知NVME;(发送CNS01h获取4096字节的固件信息等;发送CNS02h获取1024字节的namaspace list)

宝沐熙的博客 840

CodeForces - 38E Let's Go Rolling!

Description On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is

那些年 1438

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

Codeforces Beta Round #38 - E. Let's Go Rolling!

E. Let's Go Rolling!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn a number axis directed from the left rightwards, n marbles with coordinates...

Mr_Treeeee的博客 274

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Codeforces 38E.Let's Go Rolling! (dp)

On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, …, xn are situated. Let’s assume that the sizes of the marbles are infinitely small, that is in this task each of...

sakura_is_the_best的博客 308

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

动态规划-龟兔赛跑

Select Code #include using namespace std; int main() { int n, vr, vt1, vt2, L, c, t; while (cin >> L) { int p[101] = { 0 }; cin >> n >> c >> t >> vr >> vt1 >> vt2; for (int i = 0; i < n; i++

albertluf的博客 1178

POJ1276 Cash Machine

Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:37773   Accepted: 13689 Description A Bank plans to install a machine for cash withdrawal. The ma

albertluf的博客 329

POJ 3735 Training little cats(矩阵快速幂)

Training little catsTime Limit: 2000MS Memory Limit: 65536KTotal Submissions:14975 Accepted: 3708DescriptionFacer's pet cat just gave birth to a brood of little cats. Having considered the health of t...

albertluf的博客 309

POJ 3046 Ant Counting(多重集组合数)(基础组合dp)

Ant Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6467   Accepted: 2397 Description Bessie was poking around the ant hill one day watching the ant

albertluf的博客 308

HDU 1087 Supper Jumping!Jumping!Jumping!(记忆化搜索or动态规划)

Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 43519    Accepted Submission(s): 20137 Problem Descri

albertluf的博客 298

hdu 2639 Bone Collector II (01背包第K优决策)

Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5363    Accepted Submission(s): 2836 Problem Description The titl

albertluf的博客 282

HDU How many ways

How many ways Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 78   Accepted Submission(s) : 47 Font: Times New Roman | Verdana | Georgia

albertluf的博客 270

POJ 1664 放苹果(划分数)

放苹果 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 35600   Accepted: 21987 Description 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法。

albertluf的博客 258

POJ 2063 Investment

Investment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions:11335   Accepted: 3939 Description John never knew he had a grand-uncle, until he received the nota

albertluf的博客 250
上一篇: POJ 1769 Minimizing maximizer(dp+线段树)
下一篇: POJ 3735 Training little cats(矩阵快速幂)
还是太年轻
博客等级 码龄9年 53粉丝 552原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值