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

手把手教你用树莓派蓝牙抓取小米温湿度计2代数据,接入HomeAssistant(附密钥获取避坑指南) 本文详细介绍了如何通过树莓派蓝牙抓取小米温湿度计2代数据并接入HomeAssistant的完整流程。重点解析了获取32位加密密钥的三种方法,包括使用Telink Flasher工具、米家APP抓包和开源工具ATC_MiThermometer,并提供了HomeAssistant集成配置和常见问题排查指南,帮助用户实现稳定可靠的温湿度监测。 阅读详情

题目:

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;
}
保姆级教程:在Rockchip RK3588 SDK中,如何为你的新硬件板子创建第一个DTS文件 本文提供在Rockchip RK3588 SDK中为自定义硬件创建首个DTS文件的详细教程。通过分析DTS在RK3588开发中的角色、快速定位参考设计、实操步骤及调试验证方法,帮助开发者高效完成硬件板级配置,特别适合嵌入式Linux系统开发者参考。 阅读详情

相关推荐

PostgreSQL+Citus分布式集群实战:从零搭建到性能调优

本文详细介绍了如何从零开始搭建并优化PostgreSQL+Citus分布式数据库集群。内容涵盖集群规划、源码编译安装、Citus扩展部署、节点配置、分布式表创建以及核心性能调优策略,为应对海量数据增长提供了完整的部署指南和实战解决方案。

oo7890的博客 634

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的博客 436

VisionMaster 4.2.0安装

按照顺序安装。

XuXing_java的专栏 3927

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的博客 598

使用C++编写一个可视化窗口

初学C++时,控制台会给我们提供一个黑窗口,而这篇文章所做的就是:创建一个属于图形界面窗口,而不是使用控制台黑窗口 如图,这是一个标题为XSZY的窗口 看完这篇文章,你想要的窗口大小,图标等都可以自己定义 甚至是在窗口上鼠标的样子,都是可以随意改的 所有有关视窗的基本函数和类型都定义在头文件 <windows.h> 中 我们只需要引用就好了 //引用头文件 windows.h #include<windows.h> 然后定义程序的入口函数main int __stdcall W

XSZY_的博客 6万+

卡尔曼滤波算法-Kalman Filter Algorithm

Kalman滤波是一种递归过程,主要有两个更新过程:时间更新和观测更新,其中时间更新主要包括状态预测和协方差预测,主要是对系统的预测,而观测更新主要包括计算卡尔曼增益、状态更新和协方差更新,因此整个递归过程主要包括五个方面的计算:1)状态预测;2)协方差预测;3)卡尔曼增益;4)状态更新;5)协方差更新; 用数学公式表示,如下: 状态预测:(1) 其中,X(k|k)是k时...

sunlin972913894的博客 2万+

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

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

DevourPower的博客 355

离线反激转换器反馈环路设计:从理论到实践的Type II补偿器详解

在开关电源设计中,反馈环路稳定性是决定电源性能与可靠性的核心。其本质是通过补偿网络对功率级的小信号特性进行校正,以构建一个具有足够相位裕度和增益裕度的闭环系统。反激转换器作为一种广泛应用的隔离拓扑,其功率级在连续导通模式(CCM)和非连续导通模式(DCM)下呈现不同的零极点特性,这直接决定了补偿器的选型。Type II补偿器因其传递函数中固有的积分环节、低频零点与高频极点,恰好能与反激功率级的1P2Z(一个极点、两个零点)特性形成互补,有效塑造理想的回路增益曲线,实现快速稳定的动态响应。本文聚焦于采用TL4

weixin_30162121的博客 518

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

因果强化学习:优化决策策略的因果方法

1. 背景介绍 1.1 传统强化学习的局限性 强化学习(Reinforcement Learning, RL)是一种通过与环境交互来学习最优决策策略的方法。然而,传统强化学习方法在面对复杂、动态和不确定的现实世界问题时,往往存在以下局限性: 数据效率低:传统强化学习方法

AI天才研究院 663

【推荐100个unity插件】实现逼真的雪与雨系统——Weatherade: Snow and Rain System

Weatherade是一款Unity雪天/雨天场景创建系统,支持内置RP和URP渲染管线,提供雪/雨覆盖着色器、地形支持、雪痕效果等特性。安装后需配置URP渲染器,通过添加覆盖实例和转换材质实现效果,支持手动调整或批量转换工具快速应用。系统包含完整演示场景,可通过官方文档了解更多配置细节。下载地址:Unity Asset Store或百度网盘学习版。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 1237

排位赛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

泛微OA集成阿里云短信(E9保姆教程)

泛微OA集成阿里云短信(E9保姆教程)

技术分享 521

【校队排位赛#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

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

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

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

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的博客 3815

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

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

林苏泽 381

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_的博客 441

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

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

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

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

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的博客 703

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

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

DevourPower的博客 559

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的博客 526
上一篇: 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、付费专栏及课程。

余额充值