GDUT_排位赛题解报告_第2场_B. Snakes

ScanNet数据集下载全攻略:从申请到解析的保姆级教程(含常见问题解决) 本文提供了ScanNet数据集从申请授权到下载、解析的完整实战指南。针对这个大规模室内RGB-D数据集,详细介绍了官方申请流程、优化下载策略、数据验证方法,并重点解决了深度图解析等常见问题,帮助三维视觉研究者高效获取和使用这一宝贵资源。 阅读详情

题目:

B. Snakes
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
According to legend, St. Patrick banished all of the snakes in Mooland over a thousand years ago. However, snakes have since made their way back to Mooland! St. Patrick’s day was on March 17, so Bessie is going to commemorate St. Patrick by banishing all of the snakes from Mooland once and for all. Bessie is equipped with a net to capture snakes distributed in N groups on a line (1≤N≤400). Bessie must capture every snake in every group in the order that the groups appear on the line. Each time Bessie captures a group, she can put the snakes in a cage and start with an empty net for the next group.

A net with size s means that Bessie can capture any group that contains g snakes, where g≤s. However, every time Bessie captures a group of snakes of size g with a net of size s, she wastes s−g space. Bessie’s net can start at any size and she can change the size of her net K times (1≤K<N).

Please tell Bessie the minimum amount of total wasted space she can accumulate after capturing all the groups.

Input
The first line contains N and K. The second line contains N integers, a1,…,aN, where ai (0≤ai≤106) is the number of snakes in the ith group.

Output
Output one integer giving the minimum amount of wasted space after Bessie captures all the snakes.

Example
inputCopy
6 2
7 9 8 2 3 2
outputCopy
3
Note
Bessie’s net starts at a size of 7. After she captures the first group of snakes, she changes her net to a size of 9 and keeps that size until the 4th group of snakes, when she changes her net to size 3. The total wasted space is (7−7)+(9−9)+(9−8)+(3−2)+(3−3)+(3−2)=3.

这个题目题意就是,给出一个序列,然后让你画k条水平线,要求水平线数字大于它盖住的数字,求水平线面积 - 数字和 的最小值。

做法是一个dp,用dp[i][j]表示前i个数,变了j次时候求得的最小差值。
我们用前缀和qzh[i]来表示前i个数字和,可以容易求得dp[i][0]等于多少:
定义一个maxn意义为最大值,边更新边赋值dp[i][0]=maxn*i - qzh[i]。

然后就可以开始转移方程:dp[i][j]等于多少呢?

我们假设有dp[s][j-1],这个东西就是dp[i][j]的前身,也就是第s+1个数到第i个数的答案加上dp[s][j-1]就是dp[i][j]了,那么这样的话,我们就枚举s,s到底是谁?
我们从j开始枚举,因为对于一个dp[i][j],j肯定是<=i的,i个数,j个水平线嘛,然后就是一个n^3的二维dp,只有400个数,那么问题就解决了。
代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <climits>
#include <queue>
#include <stack>
#include <map>
//鬼畜头文件
using namespace std;
const int INF = 0x3f3f3f3f;//1.06e9大小
const int mod = 1e9+7;
typedef unsigned long long ULL;
typedef long long LL;
//鬼畜define
int n,k;
int qzh[401];
int all[401];
int dp[401][401];
 
int main()
{
	scanf("%d %d",&n,&k);
	qzh[0]=0;
	for(int time=1;time<=n;time++)
	{
		scanf("%d",&all[time]);
		qzh[time]=qzh[time-1]+all[time];
	}
	for(int time=1;time<=n;time++)
	{
		for(int time1=1;time1<=n;time1++)
		{
			dp[time][time1]=INF;
		}
	}
	int maxn=all[1];
	for(int time=1;time<=n;time++)
	{
        maxn=max(maxn,all[time]);
        dp[time][0]=time*maxn-(qzh[time]-qzh[0]);
    }
    for(int j=1;j<=k;j++)
	{
        for(int i=j+1;i<=n;i++)
	{
            maxn=all[i];
            for(int s=i-1;s>=j;s--)
            {
                maxn=max(maxn,all[s+1]);
                dp[i][j]=min(dp[i][j],dp[s][j-1]+maxn*(i-s)-(qzh[i]-qzh[s]));
            }
        }
    }
 
    printf("%d\n",dp[n][k]);
    return 0;
}
电力电子新手必看:COT控制模式的工作原理与典型应用场景解析 本文深入解析了COT控制模式的工作原理及其在电力电子领域的典型应用。COT控制(恒定导通时间控制)通过固定导通时间机制,解决了传统滞环控制的问题,特别适用于需要快速瞬态响应和高效率的应用场景,如CPU/GPU供电和便携设备电源管理。文章详细介绍了COT控制的核心流程、技术特点及设计实践中的关键考量,帮助电力电子新手快速掌握这一技术。 阅读详情

相关推荐

机器视觉检测到底怎么做,经验分享

笔者做机器视觉检测已经有五六年了,也算是对机器视觉的检测技术有了一定的掌握。总的来说,基于机器视觉的检测技术主要包含三个部分:视觉采集模块、后台分析模块和动作决策模块。这几个分类,跟教科书上的有较大差异,很多同学觉得我在杜撰。笔者也不作反驳,因为这是笔者这些年工作经验的总结,自然区别于教科书。下面我们分开来讲这几个模块,同时会把笔者之前的论文做个推荐总结。 所有文章均可在博主的主页中找到,若无法找到,可以用搜索工具。博主的主页: https://blog.csdn.net/Aoulun 第..

Aoulun的博客 8677

GDUT_排位赛题解报告_第3场_D. Race

Bessie is running a race of length K (1≤K≤109) meters. She starts running at a speed of 0 meters per second. In a given second, she can either increase her speed by 1 meter per second, keep it unchang...

DevourPower的博客 435

格(Lattice)基础(一)

有关格的基础概念,和相关的格难题

Amire0x的小乐园 5698

GDUT_排位赛题解报告_第4场_E. Binary Tree

题目: In computer science, a binary tree is a rooted tree in which each node has at most two children. In this problem, let’s denote n as the number of nodes, l as the number of leaf nodes and h as the ...

DevourPower的博客 597

【RTOS】 Vxworks 653 第一章 —— 初识 vx653 3.x

。。不是很重要,自己搜吧鲁棒分区是一种确保共享计算资源中独立运行功能实现​​时空隔离​​的机制,其目标是为集成模块中的混合临界性应用提供与联邦式部署(federated implementation)同等级别的功能隔离保障。具体表现为:​​多关键性共存​​:支持不同安全等级应用(如飞控系统A级与娱乐系统D级)在同一模块中协同运行。​​抗干扰能力​​:防止未授权或意外的时空干扰(如内存越界、时间窗口冲突),确保应用间互不影响。​​。

qq_38183694的博客 1280

vivado2020.1使用vitis生成QSPI启动文件报错

在使用vivado2020.1使用vitis,生成QSPI启动文件时会报错,data2mem命令无法识别,这是因为data2mem是xilinx7series芯片的命令,当使用ultrascale/ultrascale+芯片时则需要使用updatemem命令,这或许是vitis的一个bug吧,明明选择的是ultrascale的芯片,却一直调用打她mem命令,挺麻烦的,需要手动执行,在XSCT console窗口执行的命令如下: updatemem -force -meminfo \ F:/xc7z35t/x

qq_32134427的博客 2336

GDUT_排位赛题解报告_第5场_C. 积木

题目: ChenJr已经两个月没有出门了,因此他已经无聊到开始用积木来玩搭房子游戏了。 ChenJr首先规定,对于搭建的每一栋房子,他只能选取长度为n的积木作为地基,之后他根据下述的规则进行搭建。 如果当前搭建的房子的最顶端的积木块的长度为k,那么ChenJr可以选择一个正整数i,(i∈[1,k2]),并在房子顶端放置一个长度为i的积木。或者ChenJr可以选择不再继续放置积木,代表当前的房子已经...

DevourPower的博客 354

GD32F303定时器配置:实现两路互补PWM输出与相位控制

本文详细解析了基于GD32F303定时器实现两路互补PWM输出与精确相位控制的方法。通过配置TIMER2的中间对齐模式,结合REMAP功能解决引脚复用问题,从硬件层面稳定生成相位差180度的互补PWM信号,适用于电机驱动、开关电源等对时序要求苛刻的应用场景。

weixin_29182481的博客 304

Snakes【区间DP】Rating

题目描述: According to legend, St. Patrick banished all of the snakes in Mooland over a thousand years ago. However, snakes have since made their way back to Mooland! St. Patrick’s day was on March 17, so...

weixin_45619734的博客 237

(一)PyBullet机器人仿真入门:从环境搭建到实例解析

本文详细介绍了PyBullet机器人仿真平台从零开始的完整入门指南。内容涵盖环境搭建、官方示例解析、核心操作(连接、世界与模型)、关节控制与状态读取,以及碰撞检测、传感器模拟等高级功能,帮助读者快速掌握这一强大的机器人仿真工具。

weixin_29062865的博客 1379

东北大学计算机预推免(双非友好)

东北大学,个人觉得在985里面对双非比较友好,而且学校的计算机专业实力也比较强,上岸难度不算很大,可以重点关注一下。学校复试审核的时间比较早,拿到复试资格之后,一定要留意报名系统首页中计算机学院的信息,学校也会在全国各地不同时间安排面试,可以根据自己的情况选择一个合适的时间前去面试,并且有对应面试场次的QQ群,信息会在群里面发布。面试成绩会在预推免系统中直接公布,但是是否拟录取不会公布,需要考生自行判断,今年计算机学院录取线定在了86分左右,最终递补下来,好像录取到了84分左右。

D1379951481的博客 3120

排位赛2-Snakes

排位赛2-Snakes 题目 According to legend, St. Patrick banished all of the snakes in Mooland over a thousand years ago. However, snakes have since made their way back to Mooland! St. Patrick’s day was on Mar...

weixin_45600829的博客 282

开源免费!ReaLTaiizor如何用MIT许可证打造专业级WinForm UI?

摘要: ReaLTaiizor是一款开源UI控件库,为WinForm应用提供现代化界面解决方案。支持100+组件、多主题切换(浅色/深色/自定义)和.NET 4.8-8.0全版本兼容,MIT许可证允许免费商用。通过NuGet快速安装,3步改造传统界面:1)注入主题(如this.Theme = new Dark()),2)替换原生控件为高颜值组件(如ModernGrid替代DataGridView),3)集成高级功能(分页/动画提示)。典型场景包括登录界面美化(进度动画+通知控件)和数据表格Material风

墨夶的博客 1521

Snakes(并查集)

Snakes Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u POJ 2588 Description Buffalo Bill wishes to cross a 1000x1000 square field. A number of snakes a

沧6月的专栏 1186

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

WINCC7.3破解文件

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

B. Jumps(模拟)

B. Jumps time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are standing on the OX-axis at point 0 and you want to move to an integer point x>0. You can make several jumps. Suppose you’re current

林苏泽 380

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

GDUT 第二场排位赛

G. Snow Boots 题目链接:http://codeforces.com/group/NVaJtLaLjS/contest/238204/problem/G time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output It’s winter ...

Slime 696

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

usaco Snakes (dp)

题面: According to legend, St. Patrick banished all of the snakes in Mooland over a thousand years ago. However, snakes have since made their way back to Mooland! St. Patrick’s day was on March 17, so ...

冰柠橙的博客 429

codeforces 排位赛1

传送门 题面 A. Cow Gymnastics time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output In order to improve their physical fitness, the cows have taken up gym...

cym_的博客 439

GDUT 第一次排位赛

A. The Bucket List time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Farmer John is considering a change in how he allocates buckets for milking ...

Slime 575

cfB. Luba And The Ticket time limit per test2 seconds memory limit per test256 megabytes inputstanda

B. Luba And The Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Luba has a ticket consisting of 6 di

Dosth_Magic 5068

C. Chessboard time limit per test1 second memory limit per test256 megabytes inputstandard input out

C. Chessboardtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMagnus decided to play a classic chess game. Though what he saw in his locker shocked ...

SunMoonVocano的博客 3814

【校队排位赛#10 D】 Codeforces Hard Process 二分

Hard Process time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are given an array a with n elements. Each element of a is either 0 or 1. Let’...

待到山花烂漫时 220

GDUT_寒假训练题解报告_专题I_L题 个人题解报告

GDUT_寒假训练题解报告_专题I_L题 个人题解报告 题目: You are given two integers a and b. You may perform any number of operations on them (possibly zero). During each operation you should choose any positive integer x and...

DevourPower的博客 880

GDUT_寒假训练题解报告_专题I_K题 个人题解报告:杭电题目Error Curves【裸三分】

GDUT_寒假训练题解报告_专题I_K题 个人题解报告 题目: Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a method called Linear Discriminant Analysis, which has many interesti...

DevourPower的博客 702

GDUT_寒假训练题解报告_专题I_A题 个人题解报告【尺取模板题目详解】【poj题目Subsequence】

GDUT_寒假训练题解报告_专题I_A、B、C、D题 个人题解报告 A题:尺取(模板题目 给出了一个N个正整数序列(10<N<1e5),每个正整数小于或等于10000,以及一个正整数S(S<1e8)。编写一个程序,以求序列的连续元素的子序列的最小长度,其和大于或等于S。 输入 第一行是测试用例的数量。对于每个测试用例,程序必须从第一行读取数字N和S,用间隔分隔。序列的数目在测试用...

DevourPower的博客 557

GDUT_排位赛题解报告_第3场_H. Photoshoot

题目: Farmer John is lining up his N cows (2≤N≤103), numbered 1…N, for a photoshoot. FJ initially planned for the i-th cow from the left to be the cow numbered ai, and wrote down the permutation a1,a2,…...

DevourPower的博客 525
上一篇: GDUT_排位赛题解报告_第1场_E题 Milk Visits
下一篇: GDUT_排位赛题解报告_第2场_H. I Would Walk 500 Miles
DevourPower
博客等级 码龄7年 52粉丝 78原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值