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

『杭电1824』Let‘s go home Problem Description 小时候,乡愁是一枚小小的邮票,我在这头,母亲在那头。 —— 余光中 集训是辛苦的,道路是坎坷的,休息还是必须的。经过一段时间的训练,lcy决定让大家回家放松一下,但是训练还是得照常进行,lcy想出了如下回家规定,每一个队(三人一队)或者队长留下或者其余两名队员同时留下;每一对队员,如果队员A留下,则队员B必须回家休息下,或者B留下,A回家。由于今年集训队人数突破往年同期最高记录,管理难度相当大,lcy也不知道自己的决... 阅读详情

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.

Examples
input
Copy
3
2 3
3 4
1 2
output
5
input
Copy
4
1 7
3 1
5 10
6 1
output
11


题意:

给你n个球,一开始球都往左滚,使球停止有两种方法。

1.把它钉起来,给你一个花费。

2.让它滚到钉起来的球旁边。花费为距离。

让你求使所有球停止的最少花费。


POINT:

dp[i],代表钉下i这个球后(1-i)球的最少花费。

打表cost[i][j]数组代表,j+1到i这些球全部滚到j这个球上的距离。


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int maxn = 3333;
#define LL long long
struct node
{
    LL x,cost;
    friend bool operator < (node a,node b)
    {
        return a.x<b.x;
    }
}a[3333];
LL cost[maxn][maxn];
LL dp[maxn];
int main()
{
   LL n;
   scanf("%lld",&n);
   for(LL i=1;i<=n;i++){
        scanf("%lld%lld",&a[i].x,&a[i].cost);
   }
   sort(a+1,a+1+n);

   for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            cost[j][i]=a[j].x-a[i].x;
        }
        for(int j=i+1;j<=n;j++){
            cost[j][i]+=cost[j-1][i];
        }
   }

   /*for(int i=1;i<=n;i++){
    for(int j=i+1;j<=n;j++){
        printf("%lld  ",cost[j][i]);
    }
    printf("\n");
   }*/
   dp[1]=a[1].cost;
   for(int i=2;i<=n;i++){
        dp[i]=13278126378612783;
        for(int j=1;j<i;j++){
            dp[i]=min(dp[i],dp[j]+cost[i-1][j]+a[i].cost);
        }
   }
    LL Min=13278126378612783;
    for(int i=1;i<=n;i++){
        Min=min(dp[i]+cost[n][i],Min);
    }
    printf("%lld\n",Min);




    return 0;
}



【EB-03】 AUTOSAR builder与EB RTE集成 打开EB工具后,在EB的步骤是:执行MultiTask(2)-> Mapping Component to Partitions(4)->Task Mapping(5)-> SvcAs_Trigger(7)-> Code Generation(8)如涉及新增BSW Module,也需要重复以上步骤。 阅读详情

相关推荐

STM32-CubeMx-HAL库-串口空闲中断+DMA——利用HAL_UARTEx_ReceiveToIdle_DMA实现不定长数据接收

STM32-CubeMx-HAL库-串口空闲中断+DMA——利用HAL_UARTEx_ReceiveToIdle_DMA实现不定长数据接收

weixin_43864631的博客 1万+

图论--2-SAT--HDOJ/HDU 1824 Let's go home

Problem Description 小时候,乡愁是一枚小小的邮票,我在这头,母亲在那头。 —— 余光中 集训是辛苦的,道路是坎坷的,休息还是必须的。经过一段时间的训练,lcy决定让大家回家放松一下,但是训练还是得照常进行,lcy想出了如下回家规定,每一个队(三人一队)或者队长留下或者其余两名队员同时留下;每一对队员,如果队员A留下,则队员B必须...

日拱一卒,功不唐捐 2849

抖音X-Medusa风控逆向:unidbg环境重建与魔改AES还原

X-Medusa并非传统加密算法,而是深度耦合运行时环境的动态混淆系统,其核心是硬件指纹感知、线程上下文绑定与非标AES变异。理解其原理需跳出‘找密钥’思维,转向对CPU型号、系统属性、微秒级时间及内存布局的综合建模。技术价值在于将不可控的客户端风控,转化为可复现、可配置、可运维的服务化能力;典型应用场景包括合规数据采集、API协议适配与移动安全研究。本文聚焦Android native层逆向实践,基于unidbg实现高保真环境模拟,并完整还原S-Box动态生成、MixColumns矩阵变异与轮密钥XOR扰

weixin_33783283的博客 713

HDU - 1824 Let's go home(2-SAT)

题目大意:小时候,乡愁是一枚小小的邮票,我在这头,母亲在那头。 ―― 余光中 集训是辛苦的,道路是坎坷的,休息还是必须的。经过一段时间的训练,lcy决定让大家回家放松一下,但是训练还是得照常进行,lcy想出了如下回家规定,每一个队(三人一队)或者队长留下或者其余两名队员同时留下;每一对队员,如果队员A留下,则队员B必须回家休息下,或者B留下,A回家

静静地码 1280

Visual Studio 命令提示符工具区别与使用场景

Visual Studio会提供一系列命令提示符工具,这些工具应用在哪些场景呢?本文进行了相关介绍。

cicada15的博客 3507

深入解析CAN总线BusOff故障的检测与恢复机制

本文深入解析了CAN总线BusOff故障的检测与恢复机制。BusOff是CAN节点因发送错误过多而被强制离线的一种严重状态。文章详细阐述了其触发原理,即发送错误计数器(TEC)超过255,并重点介绍了通过软件实现的快慢恢复机制,以增强网络在异常情况下的稳定性和韧性。

weixin_29158047的博客 536

hdu 1824 Let's go home (2-sat)

# include # include # include # include using namespace std; # define MAXN 6010 # define MAXM 10010 struct node { int to; int next; } edge[MAXM]; int tot; int tim,num; int be[MAXN]; bool

苍竹林 692

远程桌面报‘数据加密错误‘?可能是网卡设置惹的祸(附TCP校验关闭教程)

本文深入分析远程桌面连接中出现的'数据加密错误'问题,指出网卡设置可能是根本原因,并提供详细的TCP校验关闭教程。通过禁用网卡高级属性中的'TCP校验和IPv4'与'IPv4承载卸载'功能,可有效解决RDP协议与硬件加速的兼容性问题,适用于Windows和Linux系统。

view3的博客 282

HDU 1824 Let's go home (2-SAT判断)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1824 【题目】 Problem Description 小时候,乡愁是一枚小小的邮票,我在这头,母亲在那头。                         —— 余光中 集训是辛苦的,道路是坎坷的,休息还是必须的。经过一段时间的训练,lcy决定让大家回家放松

D_Double's Journey 1719

langchain入门学习笔记

langchain快速入门

1743

YOLO26改进策略【Neck】| ICCV2025 反向卷积 Converse2D 数学逆运算提重构 + 特征域建模降伪影,提升多尺度目标检测精度

本文记录的是利用Converse2D 算子改进 YOLO26 的上采样。(Converse 2D Convolution)通过正则化最小二乘闭式解与深度化空间建模结合,实现YOLO26特征提取与上采样阶段的卷积逆运算及特征精准重构。本文利用算子,通过闭式解的非迭代计算还原卷积下采样后的原始特征,再通过可学习核与自适应正则化参数稳定逆问题求解,同时依托圆形填充与插值初始估计保留特征高频细节,对YOLO26中不同尺度检测目标的特征进行针对性重构强化、抑制卷积/转置卷积带来的伪影与信息损失干扰,在特征融合与上采样

Limiiiing的博客 666

HDU 1824 Let's go home(2-SAT)

HDU 1824 Let's go home(2-SAT) http://acm.hdu.edu.cn/showproblem.php?pid=1824 题意: 集训是辛苦的,道路是坎坷的,休息还是必须的。经过一段时间的训练,lcy决定让大家回家放松一下,但是训练还是得照常进行,lcy想出了如下回家规定,每一个队(三人一队)或者队长留下或者其余两名队员同时留下;每一对队员,如果队员A留下,则队

code 1101

【即插即用模块】注意力篇 | MICCAI 2023 | MFE:多尺度特征提取,告别固定感受野,猛涨2个点!

本文提出一种用于低分辨率乳腺癌病理图像超分辨率与分类的网络SHISRCNet。针对现有方法处理低分辨率图像效果差、感受野固定等问题,设计了多特征提取模块(MFE),通过多速率空洞卷积覆盖全尺度感受野(局部到全局),结合递进残差连接和动态权重融合机制,实现自适应多尺度特征增强。实验表明,该模块在超分辨率任务中PSNR提升近2个点,分类准确率显著提高。代码提供详细注释,支持即插即用,适用于各类多尺度视觉任务。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 217

Let's go home 【2-sat 经典作图】+【scc判定有无解】

小时候,乡愁是一枚小小的邮票,我在这头,母亲在那头。 —— 余光中 集训是辛苦的,道路是坎坷的,休息还是必须的。经过一段时间的训练,lcy决定让大家回家放松一下,但是训练还是得照常进行,lcy想出了如下回家规定,每一个队(三人一队)或者队长留下或者其余两名队员同时留下;每一对队员,如果队员A留下,则队员B必须回家休息下,或者B留下,A回家。由于今年

lzs_lazy 913

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Let's go home(HDU-1824)

Problem Description 小时候,乡愁是一枚小小的邮票,我在这头,母亲在那头。 —— 余光中 集训是辛苦的,道路是坎坷的,休息还是必须的。经过一段时间的训练,lcy决定让大家回家放松一下,但是训练还是得照常进行,lcy想出了如下回家规定,每一个队(三人一队)或者队长留下或者其余两名队员同时留下;每一对队员,如果队员A留下,则队员B...

Alex_McAvoy的博客 678

OV9734 DATASHEET,完整规格书

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

hdu 1824-Let's go home 2-SAT (模板)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1824 Let's go home Time Limit: 10000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2588Ac...

Source_Roc 347

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

HDU - 1824 Let's go home

Let’s go home Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2756 Accepted Submission(s): 1192 Problem Description 小时候,乡愁是一枚小小的邮票,我在这头,母亲在...

青烟绕指柔的博客 484

【CF套题】Educational Codeforces Round 56 (Rated for Div. 2)

【题目】 原题地址 A.Dice Rolling 只需要输出一种合法方案,且一定有解。显然输出⌊n2⌋\lfloor \frac n 2 \rfloor⌊2n​⌋即可。 #include&lt;bits/stdc++.h&gt; using namespace std; int read() { int ret=0;char c=getchar(); while(!isdigit(c)) c...

MEET YOU FIRST TIME 571

CodeForces 1093A Dice Rolling

题意: 一个骰子6个面(点数2——7),现在想拼凑一个数x(一定可以)问你要投多少次。 思路: 递推,dp[i]代表x = i要投的次数,i &lt;= 7有dp[i] = 1,否则dp[i]  = dp[i - 2] + dp[2]。 Code #include &lt;bits/stdc++.h&gt; using namespace std; const int maxn = ...

老痒的农舍 394

Let's Go

申请这个帐号已经有几个月了,因为项目繁忙都没有时间来打理这个blog, Rails的学习也缓了好长一段时间。现在我也来加入大家的行列,记录rails的学习使用历程,一起学习、交流。...

Let's Go 204

HDU 1824 Let's go home (2-SAT)

题目地址:HDU 1824 这题可以把每队的两个队员看成一个,这样就是2-sat水题了。。。 代码如下: #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define LL _

scf0920 1214

codeforces Educational Codeforces Round 56 (Rated for Div. 2) 部分题解

A. Dice Rolling 题目: 传送门A 题意: 就是求任意需要筛几次达到目标值 代码如下:   #include &lt;bits/stdc++.h&gt; using namespace std; int t; int x; int main() { scanf("%d",&amp;t); while (t--) { scanf("...

zamaochick的博客 249

UVALive 6039 Let's Go Green

树形dp。反向思维,考虑最多的情况,即所有边权和,减去没必要的,就是答案了。。。    在做减法的时候,对于一个点:     1、当存在有一条边(tmp)的权值大于通过该点所有边权值和(sum)的一半时,显然,对于除了tmp的其他边,都可以让通过tmp的自行车走这些边。所以ans -= sum-tamp。     2、当不存在上述情况时,我们就可以把通过这个点的边分成两半,这样的话对于该点就

ok_again的专栏 1557

Codeforces Round #443 (Div. 2) - C. Short Program

C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Petya learned a new programming language C

Mr_Treeeee的博客 920
上一篇: 第十四届浙江财经大学程序设计竞赛 - C Collect Jewel && G- Get the Highest Score
下一篇: AtCoder Regular Contest 095 - E Symmetric Grid
Mr_Treeeee
博客等级 码龄10年 38粉丝 551原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值