poj-3666

【POJ 3666】Making the Grade(简单DP) 首先可以明确一个方面,那就是如果将X改成Y,那么Y肯定是这N个数中的某一个(为什么仔细想想) 之后可以得到一个状态转移那就是dp[i][j]代表已经考虑了i位的情况下,结尾为j的最小更改数。 状态转移为dp[i][j] = min(dp[i-1][k] + abs(a[i] - b[j])) 这样的话可以写出一个初步的代码: #include #include #include using 阅读详情

http://vjudge.net/problem/POJ-3666

 题目是dp 题目;   简单dp 离散一下就好.

我们先来讲一讲不离散的,简单的懂了,其他的也很容易. dp[i] 代表这个数列以i 结尾的最小花费;  假设现在要求 前n个数组成的数列,那么dp[i]= 前 n-1 的 min(dp[i]~dp[0])+ (当前这个数-i);



#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>

using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
const int MAXSIZE=1e6+5;
const double eps=0.0000000001;
void fre()
{
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
}
#define memst(a,b) memset(a,b,sizeof(a))
#define fr(i,a,n) for(int i=a;i<n;i++)



const int MAXN=2010;
int a[MAXN],index[MAXN];
int dp[MAXN],temp[MAXN];
bool cmp(int x,int y)
{
	return a[x]<a[y];
}
int solve(int n)
{
	for(int i=0;i<n;i++) temp[i]=abs(a[0]-a[index[i]]);
	for(int k=0;k<n-1;k++)
	{
		int minnum=INF;
		for(int i=0;i<n;i++)
		{
			minnum=min(minnum,temp[i]);
			dp[i]=abs(a[k+1]-a[index[i]])+minnum;
		}
		for(int i=0;i<n;i++) temp[i]=dp[i];
	}
    int res=INF;
    for(int i=0;i<n;i++)
    	res=min(res,dp[i]);
    return res;
}
int main(int argc,char *argv[])
{
	int n;
	while(scanf("%d",&n)+1)
	{
		for(int i=0;i<n;i++)
			scanf("%d",&a[i]),index[i]=i;
		sort(index,index+n,cmp);
		printf("%d\n",solve(n));
	}
    return 0;
}

/**************************************************/
/**             Copyright Notice                 **/
/**  writer: wurong                              **/
/**  school: nyist                               **/
/**  blog  : http://blog.youkuaiyun.com/wr_technology  **/
/**************************************************/






MC_SetOverride指令详细应用介绍(基恩士PLC) 基恩士KV系列PLC和松下总线绝对值伺服运动控制(详细配置+轴控完整ST源代码) 阅读详情

相关推荐

从理论到实践:基于Zemax的高分辨率生物显微镜光学系统仿真与优化指南

本文详细介绍了基于Zemax的高分辨率生物显微镜光学系统仿真与优化全流程。从阿贝分辨率公式、柯勒照明等理论基础出发,逐步讲解Zemax建模、像差优化、制造可行性分析等核心步骤,并提供常见问题解决方案。通过实际案例展示如何将理论设计转化为可制造的优化方案,帮助工程师掌握从仿真到实际应用的关键技术。

weixin_29229989的博客 481

选择法

#include <stdio.h> # define MAXN 10 int main() { int i, index, k, n, temp; int a[MAXN]; scanf("%d", &n); for(i = 0; i < n; i++) { scanf("%d", &a[i]); ...

weixin_45867395的博客 3662

[小技巧] 如何复制知乎电子书中的文字和图片

文章目录一、背景二、复制文字1.最简单的方法(适合短小文字)2. 进阶方法(适合大段文字)三、复制图片四、注意事项 一、背景 有时候希望从书中摘录一部分文字作为笔记,但是知乎电子书阅读时候是禁止copy的,要么手打,要么OCR,给学习带来了一些不便。 审查元素后发现,知乎电子书是把文字分成一段一段的,试图F12直接copy不太方便。 本问将以谷歌Chrome浏览器为例,给出复制小技巧。 二、复制文字 1.最简单的方法(适合短小文字) 选中你需要的文字,左键单击不放,直接拖到地址栏。 然后可以从地址栏中

江南蜡笔小新 9246

习题7-1 选择法排序 (20分)

习题7-1 选择法排序 (20分 本题要求将给定的n个整数从大到小排序后输出。 输入格式: 输入第一行给出一个不超过10的正整数n。第二行给出n个整数,其间以空格分隔。 输出格式: 在一行中输出从大到小有序的数列,相邻数字间有一个空格,行末不得有多余空格。 输入样例: 4 5 1 7 6 输出样例: 7 6 5 1 #include<stdio.h> int main() { int i, index, k, n, temp; int a[10]; scanf("%d", &n); fo

weixin_45863084的博客 374

Minitab实战:用Weibull分布预测产品寿命的5个关键参数(附真实案例)

本文通过一个真实的电容器老化测试案例,详细介绍了如何运用Minitab软件进行Weibull分布分析,以预测产品寿命。文章深入解读了形状参数β、尺度参数η等五个关键参数的工程意义与商业价值,指导工程师从失效数据中提取洞察,并将其应用于可靠性评估、保修策略制定及成本预估等实际业务决策。

weixin_29231263的博客 520

C# WPF多页面间的数据共享(经典)

实现页面间的数据共享有很多方法,比如:①事件的发布订阅 ②委托③ioc容器④静态类等,这节主要通过静态的集合实现数据的添加和获取。

sf315418的博客 639

POJ3666

题目来源:http://poj.org/problem?id=3666 题意:给定一个序列,可以对序列的任意一个数进行加减,使之序列成为一个不递增或者不递减的序列,改变数值1就花费价值1,问使之序列成为一个不递增或者不递减的序列最少需要多少价值。 思路:一开始看完题目,想对每个数进行分状态取递增或者递减,当到i时比较之前i-1的数值是多少,但是之前数值可取许多种不同的情况,i也有许多可取的数字...

weixin_43958964的博客 586

别再凭感觉选电容了!手把手教你计算电机控制器里的母线电容(附Excel计算工具)

本文详细解析了电机控制器中母线电容的选型方法,从理论计算到工程实践,帮助工程师避免常见误区。通过精确计算纹波电压、电容容量等关键参数,并结合薄膜电容与电解电容的性能对比,提供实用的选型建议。附带的Excel计算工具可快速完成参数计算,适用于工业伺服驱动和电动车电机控制器设计。

weixin_28720573的博客 518

POJ 3666 dp

题意 传送门 POJ 3666 基本思路是对 N 个位置枚举所有可能高度,并 dp 求最大值。可能高度取 N 个位置的高度即可,排序以方便顺序 dp。对于升序的情况 dp[i][j]=max{dp[i−1][j′]}+abs(B[j]−A[i]),j′≤jdp[i][j]=max\{dp[i-1][j']\}+abs(B[j]-A[i]),j'\leq jdp[i][j]=max{dp[i−1][...

neweryyy的博客 184

PCIe(二) —— 配置空间

好了,这一篇我们把配置空间的结构,分配和访问,都大概总结了一遍,并且还介绍了它们的头部字段和这些字段的意义,包括BAR和消息路由的原理。之后,如果有时间,我们会继续来探索PCIe的数据报文的结构和传输等等。

叫好与叫座虽然不是对立面,但想在同一个作品中达到双重效果很难。 1767

600份国家自然基金申报书--模板

600份国家自然基金申报书--模板

需要远程指导仿真实验、代码有问题的,请后台私信或者关注公众号 4186

POJ 3666(DP)

题目链接:http://poj.org/problem?id=3666   题目大意:给一个串,要求修改最少使得串满足非递增或非递减   题目思路:刚开始没想到,后来经学长提醒如果串里的数字变1000可以怎么做。然后发现可以开dp[i][j][k]暴力,i表示第几位,j表示第几大,k表示是递增还是递减(最后的代码直接两种情况分开来算了),然后转移就是dp[i][j][k]=dp[i-1][...

smilestruggler_Fly To Higher 378

视觉Transformer实战 | Vision Transformer(ViT)详解与实现

在计算机视觉领域,卷积神经网络 (CNN) 长期以来一直是处理图像任务的主流架构。然而,随着 Transformer 在自然语言处理领域的巨大成功,研究人员开始探索将这种基于自注意力机制的架构应用于视觉任务。Vision Transformer (ViT) 是这一探索的重要里程碑,它首次证明了纯 Transformer 架构在图像分类任务上可以超越最先进的 CNN 模型。本文将详细介绍 ViT 的技术原理,并使用 PyTorch 从零开始构建 ViT 模型用于图像分类任务。

盼小辉丶的博客 4万+

POJ3666 nlogn 做法

呜呜呜我再也不会放弃一个我能理解的题了!就算花几个小时!就算手里还有很多题! 给你一个序列,每次操作你可以让一个数加一或者让一个数减一,问使这个序列不减的最小操作数(具体是啥我也不想看了,大概就是这样,如果是严格递增a[i] - i就变成了不减) 然后有一个结论是改变之后的序列的每个数,一定是原来序列中的某个数。那么离散化之后的n ^2 DP就很显然了 但是!!有一个极其巧妙的nlogn的解...

swunHJ的博客 443

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

poj 3666

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int SIZE = 2010; int a[SIZE], c[SIZE], nums[SIZE]; int f[SIZE][SIZ...

weixin_30443075的博客 67

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

POJ3666 线性dp+维度优化

以下内容部分摘自《算法竞赛进阶指南》(lyd),也有个人的理解

Time Limit Exceeded on test 99 258

深度学习工具包 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")

poj3666

poj 3666 Making the Grade 题目链接:http://poj.org/problem?id=3666 参考:https://blog.youkuaiyun.com/wuyanyi/article/details/7255154 题意 给定一个序列,以最小代价将其变成单调不增或单调不减序列 问题分析 dp[i][j] := 前i+1个数构成的序列,且序列的最大值为j,dp[i][j]代...

fkuner的博客 349

poj3666(基础dp+离散化)

题目链接:http://poj.org/problem?id=3666Making the GradeTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 9118 Accepted: 4261DescriptionA straight dirt road connects two fields on FJ's farm, but it...

star_moon0309的博客 3150

poj3666(DP+离散化)

题目链接:http://poj.org/problem?id=3666 思路: 看了讨论区说本题的数据比较弱,只需要考虑不减序列即可,比较懒,所以我也只写了这一部分的代码,思路都一样,能AC就行了。 首先要想明白一点,就是将每一个elevation更新后的值一定是原来存在的,因为更新一个elevation最好是与前一个相等,要么与后一个相等,可以从贪心角度去想,这里要先明白,很重要。所以我们...

weixin_33812433的博客 208

POJ3666 Making the Grade

POJ3666 Making the Grade 题意: 给定一个长度为n的序列A,构造一个长度为n的序列B,满足b非严格单调,并且最小化S=∑i=1N|Ai-Bi|,求出这个最小值S,1<=N<=2000,1<=Ai<=1e9. 引理:在满足S最小化的情况下,一定存在一种构造序列B的方案,使得B中的数值都在A中出现过。 由此,用一个数组b[i...

weixin_34163741的博客 176

[POJ 3666]Making the Grade[DP]

题目链接:[POJ 3666]Making the Grade[DP] 题意分析: 含有n个数的序列,允许对序列中的任意一个数加或者减,问:最少更改多少值,使得原序列变成单调递增或者单调递减? 解题思路: 设状态dp[i][j]为到第i个数,以b[j]为结尾更改的最少价值。那么有转移方程dp[i][j]=min(dp[i−1][k])+|a[i]−b[j]|(k=0∼j)dp[i][j] =

闲停 498

POJ 3666 DP

&#13; 链接:&#13; http://poj.org/problem?id=3666&#13; 题意:&#13; 给你一个序列,求使它变成非递增或者非递减所需的最少花费&#13; 把a变成b的花费为|a-b|&#13; 题解:&#13; 事先知道了测试数据都是非递减的,所以就只写了非递减的,其实求非递增在反一下算一遍取最小值就行了&#13; dp[i][j]表示第i个数...

花海 111

动规-POJ-3666

http://poj.org/problem?id=3666 Making the Grade 给定一个正整数数列,要求通过对每一个元素加上或减去任意值,使得数列非严格递增(虽然题设要求还可以非严格递减,但是实际数据只要求非严格递增)。 求所得数列与原数列各个对应元素差的绝对值之和的最小值。 解题报告 思路 由于要求最终改变的绝对值和最小,所以可以知道所得解的数列中元素的最大...

dinghua4921的博客 184
上一篇: HDU-2255(KM算法)
下一篇: 2016-浙江理工新生赛-部分题解
Code--Dream
博客等级 码龄11年 53粉丝 100原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值