题目 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…
题目链接   Sonya and Problem Wihtout a Legend 题意  给定一个长度为n的序列,你可以对每个元素进行$+1$或$-1$的操作,每次操作代价为$1$. 求把原序列变成严格递增子序列的所需最小花费. 考虑$DP$. 首先比较常见的套路就是把每个$a[i]$减去$i$,然后把这个新的序列升序排序,记为$b[i]$. 这里有个结论:最后操作完成之后的每个数都是$b[i]$中的某个数. 然后就可以$DP$了,令$f[i][j]$为前$i$个数操作之后每个数都小于等于$b…
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…
题目链接: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大的数字的最…
题意:给你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]来表示…
题意:给你一个数列,对于每个数字你都可以++或者−− 然后花费就是你修改后和原数字的差值,然后问你修改成一个严格递增的,最小花费 思路:很久以前做过一道一模一样的 严格递增很难处理,就转化为非严格递增处理 设a[i]<a[j],i<j a[j]-a[i]>=j-i a[j]-j>=a[i]-i 即将a[i]转化为a[i]-i处理 非严格递增情况下最终数列一定是由原先的数组成的,不可能出现某两个原数中间的值 dp[i,j]为第i位,结尾为第j大的数,转化成这样的数列的最小费用 dp[…
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…
[题目]C. Sonya and Problem Wihtout a Legend [题意]给定n个数字,每次操作可以对一个数字±1,求最少操作次数使数列递增.n<=10^5. [算法]动态规划+前缀和优化 [题解]★令b[i]=a[i]-i,则a[i]递增等价于b[i]不递减. 这样做之后,显然数字加减只能到b[i]中出现的数字,而不会出现其它数字. 令f[i][j]表示前i个数,第i个数字大小为c[j](第j大的数字)的最少操作次数. f[i][j]=abs(b[i]-c[j])+min{f…
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…
题目链接: 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…
//把一个序列转换成严格递增序列的最小花费 CF E - Sonya and Problem Wihtout a Legend //dp[i][j]:把第i个数转成第j小的数,最小花费 //此题与poj 3666相似 a[i]转换成a[i]-i #include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <vector> #inclu…
Sonya and Problem Wihtout a Legend 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 b…
C. Sonya and Problem Wihtout a Legend 题目连接: http://codeforces.com/contest/713/problem/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. A…
C - Sonya and Problem Wihtout a Legend 思路:感觉没有做过这种套路题完全不会啊.. 把严格单调递增转换成非严格单调递增,所有可能出现的数字就变成了原数组出现过的数字. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PII pair<int, int> #define PLI…
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…
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 i…
题意:给一个序列,可以进行若干次操作,每次操作选择一个数让它+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…
大意: 给定序列, 每次操作可以任选一个数+1/-1, 求最少操作数使序列严格递增. 序列全-i后转化为求最少操作数使序列非降, 那么贪心可以知道最后$a_i$一定是修改为某一个$a_j$了, 暴力dp即可. #include <iostream> #include <cstdio> #define REP(i,a,n) for(int i=a;i<=n;++i) using namespace std; typedef long long ll; const int N =…
这两个题是一样的,不过数据范围不同. 思路1: 在CF713C中,首先考虑使生成序列单调不下降的情况如何求解.因为单调上升的情况可以通过预处理将a[i]减去i转化成单调不下降的情况. 首先,生成的序列中的每个数一定是原序列中的数.于是可以通过dp+离散化技巧解决.dp[i][j]表示把前i个数变成单调不下降的序列,并且a[i]不超过第j大的数所需要的最小代价. 实现1: #include <bits/stdc++.h> using namespace std; typedef long lon…
考虑我们直接选择一个暴力\(dp\). \(f_{i,j} = min_{k<=j}\ (f_{i - 1,k}) + |a_i - j|\) 我们考虑到我们直接维护在整个数域上\(min(f_{i,j})\),且以\(i\)为时间维,\(j\)为变量. 我们思考我们用队列每次维护这个函数的凸壳转移点即可. 建议脑子里构思出函数图像来整理. 凸壳证明暂且不提. #include<stdio.h> #include<queue> using namespace std; int…
ZOJ Problem Set - 3829Known Notation(贪心) 题目链接 题目大意:给你一个后缀表达式(仅仅有数字和符号),可是这个后缀表达式的空格不幸丢失,如今给你一个这种后缀表达式,问最少须要多少操作能够把这个表达式变成合法的. 操作: 1.在这个表达式的不论什么位置插入''或者数字(一位数). 2.把这个表达式的不论什么两个位置的字符对换. 解题思路: 一開始想的好复杂,结果还是漏了某种情况,一直过不去:就是卡在了碰到''的时候,数字不够是插入好还是替换好. 事实上仅仅要…
Problem D: 程序填充(递归函数):数列2项和 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 2601  Solved: 2117 Description 下面程序中"____ N ____"是根据程序功能需要填充部分,请完成程序填充(注意:不得加行.减行.加句.减句,否则后果自负). 该程序功能:数列的第1.2项均为1,此后各项值均为该项前二项之和.计算数列第30项的值. #include long f(int n); void…
A * B Problem Plus HDU - 1402 (FFT) Calculate A * B.  InputEach line will contain two integers A and B. Process to end of file. Note: the length of each integer will not exceed 50000. OutputFor each case, output A * B in one line. Sample Input 1 2 10…
LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/A 题目: Description By definition palindrome is a string which is not changed when reversed. "MADAM" is a nice example of palindrome.…
lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/C 题目: Description The people of Mohammadpur have decided to paint each of their houses red, green, or blue. They've also decided that no two n…
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2066" target="_blank" style="">题目链接 题目大意:给你n种不同颜色的弹珠.然后给出每种颜色的弹珠的个数,如今要求你将这些弹珠排序,要求同样颜色的部分最多3个.然后同样颜色的弹珠称…
[POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted: 2222 Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, -, 2n. In each round of the tournament, all tea…
.navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-inverse #navbar > .navbar-nav > li > a:hover, .navbar-inverse #navbar > .navbar-nav > li > a:focus { background-image: none; background-color:…
学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门动态规划的真正意义. 奶萌兔的温馨提示:建议先理解dfs哦~(本文以一种较为新奇的方式解释DP) 动态规划 那什么是动态规划? 来问问神奇的奶萌兔吧(强行盗梗)! (奶萌兔来给你讲解啦~虽然还在睡觉=w=) 动态规划(英语:Dynamic programming,简称DP)是一种在数学.管理科学.计…