题目链接: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…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 53635    Accepted Submission(s): 21019 Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但…
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 逐个考察这个序…
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28195#problem/D 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12863    Accepted…
题目链接: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"…
Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence ( a1, a2, ..., aN) be any sequence ( ai1, ai2, ..., aiK), where 1 <= i1 < i2 < ... < iK <= N.…
求最长上升子序列长度: 单纯的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…
给定一个序列,里面的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…
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…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1257 虽然分类是dp感觉还是贪心 比较水 #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace std; +; int d[maxn]; //d数组存储一套系统的目前的发射的最小的高度…
Divide the Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 Description Alice has a sequence A, She wants to split A into as much as possible continuous subsequences, satisfying that for each subsequence, every its prefix sum is not smal…
最大的位或 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description B君和G君聊天的时候想到了如下的问题.给定自然数l和r ,选取2个整数x,y满足l <= x <= y <= r ,使得x|y最大.其中|表示按位或,即C. C++. Java中的|运算.   Input 包含至多10001组测试数据.第一行有一个正整数,表示数据的组数.…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5773 题目大意: T组数据,n个数(n<=100000),求最长上升子序列长度(0可以替代任何自然数) 题目思路: [动态规划][二分][最长上升子序列] 按最长上升子序列做,遇到0的时候更新所有长度的最优解.(这种暴力解法都能过?而且还比标解快?) // //by coolxxx // #include<iostream> #include<algorithm> #inclu…
参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你n个木块,分别给出其长度和重量,然后要对这些木块进行加工,如果木块1的长度和重量都不大于木块2, 那么这两个木块可以放在一起加工,从而只用花费1个时间单位.问要如何进行加工从而能够花费最少时间单位. 知识点: 偏序集:若一个集合A为偏序集,那么满足:1.任意一个元素X属于集合,那么这个元素X≤X 2…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5773 [题目大意] 给出一个非负整数序列,其中的0可以替换成任意整数,问替换后的最长严格上升序列长度. [题解] 由于0的任意性,因此,最后的答案,将0全部选上,是最优的,因此我们只需知道在0之间可以插入几个其余的数,记s为0的前缀和,a为数列中的数,当两个数在这个答案序列中递增当且仅当ai-si>aj-sj.所以,我们用树状数组维护ai-si最长子序列,结果加上0的个数就是答案. [代码] #…
HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 签到题,非常easy贪心得到答案是(sum + 1) / 2和ai最大值的最大值 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N =…
今年暑假不AC Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 55813    Accepted Submission(s): 30009 Problem Description “今年暑假不AC?” “是的.” “那你干什么呢?” “看世界杯呀,笨蛋!” “@#$%^&*%...”确实如此,世界杯来了,球迷的节日也来了,估计很多AC…
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now. The game can be played by two or more than two players. It consi…
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1598 一道带有贪心思想的并查集 所以说像二分,贪心这类基础的要掌握的很扎实才行. 用结构体数组储存公路编号和速度,然后按照速度从小到大的排序, 然后以每条路为起点枚举(已经排了序,所以可以保证可以取最小的),再利用并查集判断是否走到 最后比较出最小的差值 code #include<cstdio> #include<algorithm> using namespace std; ;…
Intelligence System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1650    Accepted Submission(s): 722 Problem Description After a day, ALPCs finally complete their ultimate intelligence syste…
题目无法正常粘贴,地址:http://acm.hdu.edu.cn/showproblem.php?pid=5303 大意是给出一个环形公路,和它的长度,给出若干颗果树的位置以及树上的果子个数. 起点为0,背包大小为K,求最小走多少距离能摘完所有的果子并回到起点. 观察得知,公路长度L虽然上界10^9,但果子总和最多10^5,还是可做的. 显然如果想回家时在左半边肯定逆时针返回更近,在右边同理顺时针更近. 所有取果子的操作无非三种情况(顺时针出发逆时针返回&&逆时针出发顺时针返回&…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 92493    Accepted Submission(s): 32082 Problem Description FatMouse prepared M…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 20100    Accepted Submission(s): 8909Special Judge Problem Description FatMou…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1257 Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救…
这个博客说的已经很好了.http://blog.csdn.net/shuangde800/article/details/7474903 简单记录一下自己学的: 问题就是求一个数列最长上升子序列的长度. 如果子序列长度相同,那么末尾小的子序列更有可能成为最长的子序列.所以就用一个l数组存当子序列长度为len时最小的末尾元素.如果序列下一个值比l[len]大,说明上升子序列长度增加,那么l[len++]=a[i];如果是小,就想办法把它插入到了l数组中.... HDU 1950 说白了就是求lis…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Ac code: #include<stdio.h> #include<stdlib.h> int cmp(const void *a,const void *b) { return *(int *)a-*(int *)b; } int main(void) { int n,i,ma,t; int a[3005]; while(scanf("%d",&…
题意 给出一个序列 问它的最长严格上升子序列多长 这个序列中的0可以被替代为任何数 n的范围给出了1e5 所以平常的O(n*n)lis不能用了 在kuangbin的模板里有O(nlogn)的模板 套上就可以过了 但是比赛的时候没有拿模板= =. 于是就想出了另外一个时间复杂度不明的办法= =. 将序列从前往后扫 设定一个数组a a[i]=z a[i]为当前i长度的上升子序列中的最小的尾数的大小 maxl为当前找出的最长的子序列长度 每次我们扫到一个数 都对0-maxl长度的a[i]进行判断 看能…