POJ3666 Making the Grade [DP,离散化]】的更多相关文章

题目传送门 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…
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…
传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ k ]:来到 i 位置时,所有非零数的lcm = j,当前数位 k 时含有的 Beautiful numbers 的个数. 但是,由题意得,当前的数 k 可以是个很大的数(9e18),数组根本就开不下,那怎么办呢? 将当前的数 hash 一下,如何hash呢? 假设 a,b,c,d 为[0,9]的数,那么不存…
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(DP+结论) VJ:Making the Grade HNOI-D2-T3 原题,禁赛三年. 或许是我做过的最简单的DP题了吧(一遍过是什么东西) 之前做过关于绝对值的题目,这种要求绝对值最小的题目,有一个很普遍的结论,最优解的集合中,一定有一个满足所有元素一定是所给定的元素中的元素,具体证明或许就是把括号拆开或者反证法吧. 然后就是这种看起来是\(O(n^3)\)的DP可以通过巧妙的实现降到\(O(n^2)\),当然你暴力使用数据结构变成\(O(n^2…
题目描述 给定一个序列,每次操作可以把某个数+1-1.要求把序列变成非降数列.求最少的修改次数. 输入输出样例 输入 #1 - 输出 #1 4 输入 #2 输出 #2 1 解题思路 这题是一道非常好题,一开始看了错误了E文,长久地陷入了对人生的思考(做cf的题阅读理解能力一定要好233) dp+离散化…
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…
给个$n<=2000$长度数列,可以把每个数改为另一个数代价是两数之差的绝对值.求把它改为单调不增or不减序列最小代价. 话说这题其实是一个结论题..找到结论应该就很好做了呢. 手玩的时候就有感觉,改造出来的数列的元素会不会全是原来数列里有的数?弄了几组发现没问题,但是还是踟蹰不前,不敢下手..然后我就智障的换思路了...这个故事告诉我们发现一个暂时没找到反例的结论一定要大胆实践,反正交到OJ上不要钱. 所以这题结论就上面那个.具体证明呢..我不会... 然后就简单了啊.有个很好想的状态$f[i…
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…