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]初始化=a[i],然后对b从小到大排序,用f[i][j]表示完成了B中前i个数的构造,第i个数为b[j]时的最小的S.当第i个数等于b[…
Making the Grade Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:10187   Accepted: 4724 Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ would like. His cows do not mind climbing up…
题目传送门 Making the Grade Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9090   Accepted: 4253 Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ would like. His cows do not mind climbi…
Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ would like. His cows do not mind climbing up or down a single slope, but they are not fond of an alternating succession of hills and valleys. FJ…
题目大意:给你一个序列a[1....n],让你求一个序列b[1....n],满足 bi =a && bc,则最小的调整可以是把b变成c. 所以归纳可知上面结论成立. dp[i][j] 表示考虑前i个元素,最后元素为序列中 第j小元素的最优解,a[]数组存原始数组,b[]是对a从小到大排序. dp[i][j] = MIN(dp[i-1][k]) + abs(a[i]-b[j]), (0…
POJ2279 Mr. Young's Picture Permutations 题意 Language:Default Mr. Young's Picture Permutations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2513 Accepted: 960 Description Mr. Young wishes to take a picture of his class. The students will…
layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathjax: true - kuangbin - 动态规划 传送门 A.HDU1024 Max Sum Plus Plus 题意 给你N个数,然后你分成M个不重叠部分,并且这M个不重叠部分的和最大. 思路 动态规划最大m字段和,dp数组,dp[i][j]表示以a[j]结尾的,i个字段的最大和 两种情况:1.第a[j…
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - POJ3666 题目传送门 - BZOJ1592 题意概括 整条路被分成了N段,N个整数A_1, ... , A_N (1 <= N <= 2,000)依次描述了每一段路的高度(0 <= A_i <= 1,000,000,000).FJ希望找到一个恰好含N个元素的不上升或不下降序列B_1, ... , B_N,作为修过的路中每个路段的高度.由于将每一段路垫高或挖低一个单位的花费相同,修路的总支…
问题描述 LG2893 POJ3666 题解 对于\(A\)中的每一个元素,都将存在于\(B\)中. 对\(A\)离散化. 设\(opt_{i,j}\)代表\([1,i]\),结尾为\(j\)的最小代价. \[opt_{i,j}=min_{k \in [1,m]} {opt_{i-1,k}+ |a_i-k|}\] \(\mathrm{Code}\) #include<iostream> #include<cstdio> #include<cstring> #includ…
题目大意: 给出长度为n的整数数列,每次可以将一个数加1或者减1,最少要多少次可以将其变成单调增或者单调减(不严格). 题解: 1.一开始我有一个猜想,就是不管怎么改变,最终的所有数都是原来的某个数.然而我并不会证明,然而我属于那种不彻底弄清楚就不会去写的那种顽固分子,于是就脱了好几天.网络上有很多关于此题的题解,确实用了这个猜想来离散化,但是都是讲怎么dp,然后最后扯一句“由于数据比较大,可以离散化”之类的话,要么就是相当粗略的证明(也许已经说的够清楚了只不过我没理解...). 2.今天早上起…
题意: 给定一个序列,以最小代价将其变成单调不增或单调不减序列,代价为Σabs(i变化后-i变化前),序列长度<=2000,单个数字<=1e9 输入:(第一行表示序列长度,之后一行一个表示序列第i的大小) 7 1 3 2 4 5 3 9 输出:(代价)   3 分析: 这道题有bug,只要求单调不减序列 首先,对于这种问题,我们容易想到DP 记dp[i][j]为处理到i个,最高的为j 那我们的dp[i][j]=min(dp[i-1][k])+abs(j-h[i]) (k<=j) 但是显然…
学到了一个引理:在满足S最小化的条件下,一定存在一种构造序列B的方案,使得序列B中的数值都来自于A中.(数学归纳法+中位数定理得证) 对于状态的表示来说,首先肯定有一个 i ,表示选到了第 i 个数时对应的最优解,由于需要维护序列单调性,因此需要再在状态中加入一个因素 j ,表示在第 i 位选了离散化后的A[ j ]. 状态转移为\(dp[i][j]=min\{dp[i-1][k],k\in[1,j]\}+|A[i]-B[j]|\) 代码如下: #include <cstdio> #inclu…
http://poj.org/problem?id=3666 题目大意:给n个数,每次操作可使一个数+1或-1,求最小操作数使得序列不下降或不上升. —————————————————————— 思路:http://blog.csdn.net/luovilonia/article/details/44004041 因为我再讲什么也没什么好讲的了. 但是这人的代码是错的……请注意查找最长不上升和不下降所要减的值是不一样的. #include<cstdio> #include<cstring…
给个$n<=2000$长度数列,可以把每个数改为另一个数代价是两数之差的绝对值.求把它改为单调不增or不减序列最小代价. 话说这题其实是一个结论题..找到结论应该就很好做了呢. 手玩的时候就有感觉,改造出来的数列的元素会不会全是原来数列里有的数?弄了几组发现没问题,但是还是踟蹰不前,不敢下手..然后我就智障的换思路了...这个故事告诉我们发现一个暂时没找到反例的结论一定要大胆实践,反正交到OJ上不要钱. 所以这题结论就上面那个.具体证明呢..我不会... 然后就简单了啊.有个很好想的状态$f[i…
Making the Grade Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6445   Accepted: 2994 Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ would like. His cows do not mind climbing up…
Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ would like. His cows do not mind climbing up or down a single slope, but they are not fond of an alternating succession of hills and valleys. FJ…
Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ would like. His cows do not mind climbing up or down a single slope, but they are not fond of an alternating succession of hills and valleys. FJ…
C. Efim and Strange Grade time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any po…
15.7 Imagine a simple database storing information for students' grades. Design what this database might look like and provide a SQL query to return a list of the honor roll students (top 10%), sorted by their grade point average. 在一个简化的数据库中我们有三个表,St…
It all started the summer before second grade when our moving van pulled into herneighborhood It all started (in) the summer before second grade when our moving van pulled into herneighborhood 省略了 in  语法也是根据语言习惯自己总结的东西是语言创造语法[小学]阿康(353636164)  18:58:…
Altera的-6.-7.-8速度等级逆向排序,Xilinx速度等级正向排序. 不很严密地说,“序号越低,速度等级越高”这是Altera FPGA的排序方法, “序号越高,速度等级也越高”这是Xilinx FPGA的排序方法. 从那时起,就一直没搞明白speed grade是怎么来的,唯一的概念是:同一款芯片可以有多个速度等级,不同的速度等级代表着不同的性能,不同的性能又导致芯片价格的巨大差异.脑子里总有 一个模模糊糊的推测:FPGA厂家为了提高利润,专门给同一款芯片生产了不同的速度等级. 直到…
Description 题目描述 Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives him a pack of mushrooms and ask him to grade each mushroom according to its weight. Suppose the weight of a mushroom is w, then it’s grade s is s = 10000 - (100 - w…
Grade Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 109    Accepted Submission(s): 63 Problem Description Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives him a pack of m…
Making the Grade Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4656   Accepted: 2206 Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ would like. His cows do not mind climbing up…
解题思路:这题最关键的是要读懂题意,If not all the value are the same but the frequencies of them are the same, there is no mode.这句话是至关重要 的一句.意思是:如果不是所有的值是相同的,并且他们的出现次数是相同的,那么就没有模型.如,1 1 2 2 3 3 ,它们并不是所有的数都是相同的的, 并且1出现2次,2出现2次,3出现2次,所以这组数据是没有模型的,同理,1 2 3 4 5 也是没有模型的,输…
http://acm.hdu.edu.cn/showproblem.php?pid=1084 What Is Your Grade? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9580    Accepted Submission(s): 2940 Problem Description “Point, point, life of…
Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ would like. His cows do not mind climbing up or down a single slope, but they are not fond of an alternating succession of hills and valleys. FJ…
What Is Your Grade? Problem Description “Point, point, life of student!” This is a ballad(歌谣)well known in colleges, and you must care about your score in this exam too. How many points can you get? Now, I told you the rules which are used in this co…
What Is Your Grade? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9935    Accepted Submission(s): 3041 Problem Description “Point, point, life of student!” This is a ballad(歌谣)well known in c…
最优的做法最后路面的高度一定是原来某一路面的高度. dp(x, t) = min{ dp(x - 1, k) } + | H[x] - h(t) | ( 1 <= k <= t ) 表示前 i 个路面单调不递减, 第 x 个路面修整为原来的第 t 高的高度. 时间复杂度O( n³ ). 令g(x, t) = min{ dp(x, k) } (1 <= k <= t), 则转移O(1), g() 只需在dp过程中O(1)递推即可, 总时间复杂度为O( n² ) 然后单调不递增也跑一遍…