POJ 36666 Making the Grade 简单DP】的更多相关文章

题意是: 给出n个数,让你用最小的花费将其改成非递增或非递减的 然后花费就是新序列与原序列各个位置的数的差的绝对值的和 然后可以看到有2000个数,数的范围是10亿 仔细观察可以想象到.其实改变序列中的值时,也只需要改成一个出现在原序列中的值即可 也就是说新序列中的数都是在原数列中出现过的. 那么我们可以将原数列离散化. dp[i][j] 表示将i位置的数改成离散化后第j个数时 前i个数改造成非递减序列时的最小花费 dp[i][j] = min(dp[i - 1][k]) + abs(a[i]…
题目链接: Poj 3666 Making the Grade 题目描述: 给出一组数,每个数代表当前位置的地面高度,问把路径修成非递增或者非递减,需要花费的最小代价? 解题思路: 对于修好的路径的每个位置的高度肯定都是以前存在的高度,修好路后不会出现以前没有出现过得高度 dp[i][j]代表位置i的地面高度为第j个高度,然后我们可以把以前的路修好后变成非递减路径,或者把以前的路径首尾颠倒,然后修成非递减路径.状态转移方程为:dp[i][j] = min(dp[i-1][k]) + a[i] -…
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…
题目链接: http://poj.org/problem?id=3267 从后往前遍历,dp[i]表示第i个字符到最后一个字符删除的字符个数. 状态转移方程为: dp[i] = dp[i+1] + 1;                                                 //当不能匹配时 dp[i] = std::min(dp[i], dp[msg] + (msg-i) - len[j]);  //当匹配时. 第i个字符到第msg个字符之间一共有msg-i个字符,减去…
题目链接:http://poj.org/problem?id=1050 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; ; const int INF = 0x3f3f3f; int dp[maxn]; int sum[maxn][maxn]; int ans; int main() { //freopen("…
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…
Making the Grade Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7068   Accepted: 3265 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…
True Liars Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2087   Accepted: 640 Description After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exha…
题意:输入N, 然后输入N个数,求最小的改动这些数使之成非严格递增即可,要是非严格递减,反过来再求一下就可以了. 析:并不会做,知道是DP,但就是不会,菜....d[i][j]表示前 i 个数中,最大的是 j,那么转移方程为,d[i][j] = abs(j-w[i])+min(d[i-1][k]);(k<=j). 用滚动数组更加快捷,空间复杂度也低. 代码如下: #include <cstdio> #include <string> #include <cstdlib&…
题意:农夫约翰想修一条尽量平缓的路,路的每一段海拔是A[i],修理后是B[i],花费|A[i] – B[i]|,求最小花费.(数据有问题,代码只是单调递增的情况) #include <stdio.h> #include <algorithm> #include <cstring> #include <cstdlib> #include <cmath> #include <memory> #include <iostream>…