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[…
题目链接 错解: #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; typedef long long LL; ; int a[N]; int m[N][N]; // dp[i][j] 状态结尾的值 LL dp[N][N];// 前i个元素有序最大值小于等于a[j]的最值 int n; int main () {…
题目:http://poj.org/problem?id=3666 dp方程可以是 d [ i ] [ j ] = min ( d [ i - 1 ] [ k ] ) + abs ( a [ i ] - j ),表示a数组前 i 个与结尾为 j 的 b 数组匹配的最优解.0<=k<=j. 可以证明 b 数组中的数都在 a 数组中出现过.详见<算法竞赛进阶指南>. 所以 j 可以表示a [ j ].当然为了满足不降或不升,需要复制下a数组再排个序来用. n^2是 LICS 的套路.…
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…
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…
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…
C. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output Sonya was unable to think of a story for this problem, so here comes the formal description. You are g…