http://acm.hdu.edu.cn/showproblem.php?pid=5773 题意: 求LIS,其中的0可以看做任何数. 思路: 因为0可以看做任何数,所以我们可以先不管0,先求一遍LIS,最后再加上0的个数就可以了.当然,每个数需要减去它前面0的个数. 还有这题如果用dp求LIS是要超时的,从别人那里学习了更快的求LIS的方法. 假设存在一个序列d[..] = ,可以看出来它的LIS长度为5.n 下面一步一步试着找出它. 我们定义一个序列B,然后令 i = to 逐个考察这个序…
题目链接:hdu 5773 The All-purpose Zero 官方题解:0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的. 因此我们可以把0拿出来,对剩下的做O(nlogn)的LIS,统计结果的时候再算上0的数量. 为了保证严格递增,我们可以将每个权值S[i]减去i前面0的个数,再做LIS,就能保证结果是严格递增的. 个人看法:对于显然把所以0放进去部分我解释一下: 如果0位于最长上升子序列两边,这两个零要加进去是显然的 如果有一个0夹于最长上升子序列之间,那么…
http://acm.hdu.edu.cn/showproblem.php?pid=5773 The All-purpose Zero Problem Description   ?? gets an sequence S with n intergers(0 < n <= 100000,0<= S[i] <= 1000000).?? has a magic so that he can change 0 to any interger(He does not need to ch…
Birthday Toy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 644    Accepted Submission(s): 326 Problem Description AekdyCoin loves toys. It is AekdyCoin’s Birthday today and he gets a special “…
HDU 1394 Minimum Inversion Number(线段树求最小逆序数对) ACM 题目地址:HDU 1394 Minimum Inversion Number 题意:  给一个序列由[1,N]构成.能够通过旋转把第一个移动到最后一个.  问旋转后最小的逆序数对. 分析:  注意,序列是由[1,N]构成的,我们模拟下旋转,总的逆序数对会有规律的变化.  求出初始的逆序数对再循环一遍即可了. 至于求逆序数对,我曾经用归并排序解过这道题:点这里.  只是因为数据范围是5000.所以全…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5773 0可以改变成任何数,问你严格递增的子序列最长是多少. 猜测0一定在最长上升子序列中用到,比如2 0 0 3 5 6,可以变为2 3 4 3 5 6. 那我们先算出0的个数,然后每次遇到0就把后面一开始不是0的-1,算出剩下数的最长上升子序列(nlogn),然后加上0的个数. //#pragma comment(linker, "/STACK:102400000, 102400000"…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5773 题目大意: T组数据,n个数(n<=100000),求最长上升子序列长度(0可以替代任何自然数) 题目思路: [动态规划][二分][最长上升子序列] 按最长上升子序列做,遇到0的时候更新所有长度的最优解.(这种暴力解法都能过?而且还比标解快?) // //by coolxxx // #include<iostream> #include<algorithm> #inclu…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5773 [题目大意] 给出一个非负整数序列,其中的0可以替换成任意整数,问替换后的最长严格上升序列长度. [题解] 由于0的任意性,因此,最后的答案,将0全部选上,是最优的,因此我们只需知道在0之间可以插入几个其余的数,记s为0的前缀和,a为数列中的数,当两个数在这个答案序列中递增当且仅当ai-si>aj-sj.所以,我们用树状数组维护ai-si最长子序列,结果加上0的个数就是答案. [代码] #…
The All-purpose Zero 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5773 Description ?? gets an sequence S with n intergers(0 < n <= 100000,0<= S[i] <= 1000000).?? has a magic so that he can change 0 to any interger(He does not need to change…
题意 给出一个序列 问它的最长严格上升子序列多长 这个序列中的0可以被替代为任何数 n的范围给出了1e5 所以平常的O(n*n)lis不能用了 在kuangbin的模板里有O(nlogn)的模板 套上就可以过了 但是比赛的时候没有拿模板= =. 于是就想出了另外一个时间复杂度不明的办法= =. 将序列从前往后扫 设定一个数组a a[i]=z a[i]为当前i长度的上升子序列中的最小的尾数的大小 maxl为当前找出的最长的子序列长度 每次我们扫到一个数 都对0-maxl长度的a[i]进行判断 看能…
求最长上升子序列长度: 单纯的dp时间复杂度是O(n*n)的 dp[i] = max(dp[j]+1); (0=<j<=i-1 && a[i]>a[j]) 用二分可以减少查找的时间:时间复杂度:O(n*log(n)) 模板: #define maxn 100010 int a[maxn], b[maxn]; // 二分在b[] 数组里找第一个比num 大的数的位置. int search_(int num, int low, int high) { int mid; wh…
这题想了1个多小时想不出来...方法真是精妙... 官方题解:0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的.因此我们可以把0拿出来,对剩下 的做O(nlogn)的LIS,统计结果的时候再算上0的数量.为了保证严格递增,我们可以将每个权值S[i]减去i前面0的个 数,再做LIS,就能保证结果是严格递增的. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio>…
给定一个序列,里面的0是可以任变的.问变化后最长的LIS的长度 首先,0全部选上是不亏的.这个不知道怎么说,YY一下吧. 最关键的就是解决2 0 0 3 这种问题了. 注意到这个序列的LIS应该是3 也就是你求LIS的时候,是不能包括0的,因为0是最后全部加上去的.这样你求到的LIS只能是1. 再来一组数据 2 0 0 3 0 0 4 这样的LIS是5,也就是你求到的LIS只能是1. 这样的话,只有2 1 0求到的LIS是1了. 也就是每个数减去它前面出现过多少个0,再求一次LIS. 关键要抓住…
The All-purpose Zero Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 947    Accepted Submission(s): 453 Problem Description ?? gets an sequence S with n intergers(0 < n <= 100000,0<= S[i] &l…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 Minimum Inversion Number                        Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)                                            Total Submission(s): 10…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1326 题目大意: 给n堵墙,每个墙的高度不同,求最少移动多少块转使得墙的的高度相同. 解题思路: 找到平均墙的高度(即最后墙的高度),遍历所有墙,如果小于平均墙,则用平均墙减去高度即是要移动的高度,统计所有需要"补"的高度即可.注意输出. AC Code: #include<bits/stdc++.h> using namespace std; int main() { ; w…
view code//hdu 3987 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <queue> using namespace std; typedef long long ll; const ll INF = 1LL<<59; const ll E = 100001; const int N = 10…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1394 解题报告:给出一个序列,求出这个序列的逆序数,然后依次将第一个数移动到最后一位,求在这个过程中,逆序数最小的序列的逆序数是多少? 这题有一个好处是输入的序列保证是0 到 n-1,所以不许要离散化,还有一个好处就是在计算在这个序列中比每个数大和小的数一共有多少个的时候可以在O(1)时间计算出来,一开始我没有意识到,还傻傻的用了两层for循环来每次都计算,当然这样果断TLE了.把一个数从第一个移…
Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11551    Accepted Submission(s): 4906 Problem Description There are several ancient Greek texts that contain descriptions of the fabled…
---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13003    Accepted Submission(s): 6843 Problem Description A group of researchers are designing an experiment to te…
A Walk Through the Forest 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1142 Description Jimmy experiences a lot of stress at work these days, especially since his accident made working difficult. To relax after a hard day, he likes to walk home. T…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题目让你求一个数组,这个数组可以不断把最前面的元素移到最后,让你求其中某个数组中的逆序对最小是多少. 一开始就求原来初始数组的逆序对,树状数组求或者归并方法求(可以看<挑战程序设计>P178),然后根据最前面的元素大小递推一下每次移到最后得到的逆序数,取最小值. #include <iostream> #include <cstdio> #include <cs…
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 29942    Accepted Submission(s): 10516 Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3461 A lock you use has a code system to be opened instead of a key. The lock contains a sequence of wheels. Each wheel has the 26 letters of the English alphabet 'a' through 'z', in order. If you move a…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1599 find the mincost route Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7047    Accepted Submission(s): 2736 Problem Description 杭州有N个景区,景区之间有一…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6197 题意:给你n个数,问让你从中删掉k个数后(k<=n),是否能使剩下的序列为非递减或者非递增序列 解法:签到题,就是让你求最长不下降子序列长度len,然后判断下n-len是否小于k(将序列反着存下来然后再求即最长不上升子序列,取两者len中的较大值),然后直接套nlogn的模板即可. #include <bits/stdc++.h> using namespace std; const…
爆头 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1447    Accepted Submission(s): 601 Problem Description gameboy是一个CS高手,他最喜欢的就是扮演警察,手持M4爆土匪的头.也许这里有人没玩过CS,有必要介绍一下“爆头”这个术语:所谓爆头,就是子弹直接命中对方的头部,以秒杀…
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4819    Accepted Submission(s): 2006 Problem Description There are many secret openings in the floor which are covered by a big…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1027 Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10388    Accepted Submission(s): 5978 Problem Description Now our…
Rain on your Parade Time Limit:3000MS     Memory Limit:165535KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 2389 Description You’re giving a party in the garden of your villa by the sea. The party is a huge success, and everyone is h…