题目链接   Sonya and Problem Wihtout a Legend 题意  给定一个长度为n的序列,你可以对每个元素进行$+1$或$-1$的操作,每次操作代价为$1$. 求把原序列变成严格递增子序列的所需最小花费. 考虑$DP$. 首先比较常见的套路就是把每个$a[i]$减去$i$,然后把这个新的序列升序排序,记为$b[i]$. 这里有个结论:最后操作完成之后的每个数都是$b[i]$中的某个数. 然后就可以$DP$了,令$f[i][j]$为前$i$个数操作之后每个数都小于等于$b…
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…
题目链接:http://codeforces.com/contest/713/problem/C 题解:这题也算是挺经典的题目了,这里附上3种解法优化程度层层递进,还有这里a[i]-i<=a[i+1]-(i+1),处理一下. 首先是最基础的dp[i][j]前i位最大值为j的最小值为多少. #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include…
[题目链接] http://codeforces.com/problemset/problem/713/C [题目大意] 给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上或者减去某个数,调整的代价是加上或者减去的数的绝对值之和,请你输出最小代价. [题解] 先考虑这样一个问题,如果是非严格单调递增该如何做,我们会发现每次调整,都是调整某个数字为原先数列中存在的数字,最后才是最优的,所以,我们设DP[i][j]表示前i个数字,最后一个数为原先数列排序后第j大的数字的最…
题意:给一个序列,可以进行若干次操作,每次操作选择一个数让它+1或-1,问最少要几次操作使得序列变为严格单调递增序列. 题解:首先考虑非严格递增序列,则每个数字最终变成的数字一定是该数组中的某个数.那么O(n^2)复杂度dp一下即可. dp[i][j]表示第i个数变成第j小的数,dp[i][j] = min (dp[i-1][1 ... j])+abs(a[i]-b[j]). 那么对于严格递增序列,将a[i]变成a[i]-i后,再照非严格递增序列跑一遍dp即可. #include<bits/st…
Description Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the ma…
题意:给你n个数字,每个数字可以加减任何数字,付出变化差值的代价,求最后整个序列是严格单调递增的最小的代价. 首先我们要将这个题目进行转化,因为严格单调下是无法用下面这个dp的方法的,因此我们转化成非严格的,对严格下而言,a[j]-a[i]>=j-i,那么得到a[i]-i<=a[j]-j.这样,我们令a'[i] = a[i] - i,就可以得到a'[i]<=a'[j].这样我们就把问题转化成求这样一个非严格单调的序列了. 将整个序列排序后构成一个新的数组b[i],用dp[i][j]来表示…
题目 Source http://codeforces.com/problemset/problem/713/C Description Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing n positive integers. At one turn you can pick any ele…
题目链接: 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…
E. 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…