hdu 5087 Revenge of LIS II】的更多相关文章

链接:hdu 5087 题意:求第二大的最长升序子序列 分析:这里的第二大指的是,全部的递增子序列的长度(包含相等的), 从大到小排序后.排在第二的长度 cid=546" style="color:rgb(106,57,6); text-decoration:none">BestCoder Round #16 上的第二题,注意  1 1 2 这组数据,答案应为2 思路1.每次将最长的两个上升子序列长度记录.最后再排序,取第二大的就可以 思路2.假设最长的上升子序列长度(…
http://acm.hdu.edu.cn/showproblem.php?pid=5087 题意求第二长的上升序列. 在求最长上升序列的同时加上一个数组,来记录以i为结尾的有多少条序列.如果n+1为结尾有多条,就输出dp[n+1]-1; 否则在这个最长的序列上每一个节点是不是都是num[i]==1,如果是,就输出dp[n+1]-2;否则输出dp[n+1]-1: #include <cstdio> #include <cstring> #include <algorithm&…
题意: N个数,求第二长上升子序列的长度. 数据范围: 1. 1 <= T <= 1002. 2 <= N <= 10003. 1 <= Ai <= 1 000 000 000 思路: 数据给的很暧昧,用n^2的算法可以过.故用n^2算法.只要在DP过程中记录得到f[i]是否只有一种方法即可.详看代码. 代码: int T,n; int a[1005],f[1005]; bool NOTalone[1005]; int main(){ //freopen("t…
称号:hdoj 5087 Revenge of LIS II 题意:非常easy,给你一个序列,让你求第二长单调递增子序列. 分析:事实上非常easy.不知道比赛的时候为什么那么多了判掉了. 我们用O(n^2)的时间求单调递增子序列的时候,里面在加一层循环维护sum数组.表示前面有几个能够转移当当前,求前面sum的和保存到当前. 最后求最后一个sum[n-1]是否为1就ok.为1的话在最长的基础上减一,否则就是最长的. AC代码: #include <iostream> #include &l…
DP的时候记录下能否够从两个位置转移过来. ... Revenge of LIS II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 393    Accepted Submission(s): 116 Problem Description In computer science, the longest increasing su…
Problem Description In computer science, the longest increasing subsequence problem is to find a subsequence of a given sequence in which the subsequence's elements are in sorted order, lowest to highest, and in which the subsequence is as long as po…
Revenge of LIS II Problem DescriptionIn computer science, the longest increasing subsequence problem is to find a subsequence of a given sequence in which the subsequence's elements are in sorted order, lowest to highest, and in which the subsequence…
Revenge of LIS II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 444    Accepted Submission(s): 143 Problem Description In computer science, the longest increasing subsequence problem is to fi…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目意思:找出第二个最长递增子序列,输出长度.就是说,假如序列为 1 1 2,第二长递增子序列是1 2(下标为2 3),而第一长递增子序列也是(下标为 1 3). 我一开始天真的以为,还是利用求最长递增子序列的算法啦,第二长不就是对dp 数组sort完后(从小到大)的dp[cnt-1] 啦,接着就呵呵啦----= = 题解说,要加多一个 dp 数组,以便对当前下标值为 i 的数 a[i] 为结…
题目链接:pid=5087">http://acm.hdu.edu.cn/showproblem.php?pid=5087 题意: 求第二长的最长递增序列的长度 分析: 用step[i]表示以i结尾的最长上升序列的长度,dp[i]表示到i的不同的最长的子序列的个数 然后最后推断最长的子序列的个数是否大于1是的话输出Max,否则输出Max-1 代码例如以下: #include<cstdio> #include<cstring> #include<algorith…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4996 题意:求1到n的全排列中,有多少个排列的最长上升子列长度为K? 思路:对于当前的最长上升子列,我们记录最后一个值得最小值即可.因此我们用2^n的状态表示当前最长上升子列中使用了哪些数字,且字典序最小.前n-1个数字之后,我们枚举最后一个位置的数字为[1,n]中每个数字,设为k,那么我们只要将前面[1,n-1]组成的数列中所有大于等于k的数字加一即可. int n,k; i64 f[22][22…
只要理解了LIS,这道题稍微搞一下就行了. 求LIS(最长上升子序列)有两种方法: 1.O(n^2)的算法:设dp[i]为以a[i]结尾的最长上升子序列的长度.dp[i]最少也得是1,就初始化为1,则dp[i]=max(dp[i],dp[j]+1)(其中j<i且a[j]<a[i]). int gao() { ; ;i<n;i++) { dp[i]=; ;j<i;j++) { if(a[j]<a[i]) { dp[i]=max(dp[i],dp[j]+); } } ans=ma…
Revenge of LIS II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1427    Accepted Submission(s): 489 Problem Description In computer science, the longest increasing subsequence problem is to fi…
31 Rikka with Parenthesis II (六花与括号II) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Description 题目描述 As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to…
Revenge of Nim II Problem DescriptionNim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided th…
位运算.. .. Revenge of Nim II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 229    Accepted Submission(s): 79 Problem Description Nim is a mathematical game of strategy in which two players take…
目录 题目链接 题解 代码 题目链接 HDU 4352 XHXJ's LIS 题解 对于lis求的过程 对一个数列,都可以用nlogn的方法来的到它的一个可行lis 对这个logn的方法求解lis时用的数组进行装压 预处理的到这个的转移 数位dp转移的时候直接得到下一位的lis状态 代码 #include<set> #include<cstdio> #include<cstring> #include<algorithm> #define gc getcha…
数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来,取完为止 { num1[i]=a%; //将每一个各位取出存在数组里面,实现了将数字反转 i++; //数组的变化 a/=; } 趁热打铁 例题:hdu 4554 叛逆的小明 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4554 叛逆的小明 Time…
HDU 4352 XHXJ's LIS HDU 题目大意 给你L到R区间,和一个数字K,然后让你求L到R区间之内满足最长上升子序列长度为K的数字有多少个 solution 简洁明了的题意总是让人无从下手 数字--数位DP 根据题意定义数组 第一维:数位 第二维:数位状态01串 第三维:个数K的大小 说说心路历程: 写的时候没有注意到前导零的可能型(通过看大佬的blog发现的 问题就是如何进行状态转移(手动@LC参考了LC的题解 我们用一个长度为10的二进制数表示数字几有没有被选到 如果为0,则表…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目大意:求次大LIS的长度.注意两个长度相同的LIS大小比较,下标和大的LIS较大. 解题思路: 结构体记录当前点的最大长fir,次长sec. 对于f[i].fir的转移,其实就是裸的LIS. 只不过当f[j].fir+1>=f[i].fir的时候也要转移,这时候尽管两个LIS长度相等,但是大小不一样. 对于f[i].sec的转移,首先它的初始值是0,在a[i]>a[j]条件下: ①首先…
Nim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap. ---Wi…
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5265 pog loves szh II Description Pog and Szh are playing games.There is a sequence with n numbers, Pog will choose a number A from the sequence. Szh will choose an another number named B from the rest i…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5489 给你n个数,要删去其中连续的L个,问你删去之后的LIS最大是多少? 我们先预处理出以i下标为开头的LIS,存到数组中. 然后可以枚举长为L的区间,每次移动,左边增加一个,右边删除一个. 最长上升子序列长度 = 窗口右边以右边第一个元素开头的最长上升子序列 + 窗口左边最大元素小于窗口右边第一个元素的最长上升子序列. 比如 1 2 [4 3] 2 3 5  ,  LIS = 3 + 1 = 4…
pog loves szh II Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5265 Description pog在与szh玩游戏,首先pog找到了一个包含n个数的序列,然后他在这n个数中挑出了一个数A,szh出于对pog的爱,在余下的n−1个数中也挑了一个数B,那么szh与pog的恩爱值为(A+B)对p取模后的余数,pog与szh当然想让恩爱值越高越好,并且他们…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 Problem Description In mathematics, the greatest common divisor (gcd), also known as the greatest common factor (gcf), highest common factor (hcf), or greatest common measure (gcm), of two or more i…
Rikka with Parenthesis II 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5831 Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: Correct parenthe…
Problem Description Nim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from…
开始学习最小树形图,模板题. Ice_cream’s world II Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) [Problem Description] After awarded lands to ACMers, the queen want to choose a city be her capital. This is an important event in…
A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 347161    Accepted Submission(s): 67385 Problem Description I have a very simple problem for you. Given two integers A and B, you…
http://acm.hdu.edu.cn/showproblem.php?pid=5087 求数列次长升序串的长度 还是dp求最长升序串的长度,再开一个数组记录对于dp值的串的个数 最后看一下最长字符串的个数是一个的话,显然次长的是最长的长度-1,否则就是最长的那个字符串的长度 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <stri…