#include<bits/stdc++.h> using namespace std; const int inf=1e9+5; const int maxn=1e6+5; int n,a[maxn]; int back[maxn],cnt; //log_2 n 重点数组,记录长度为cnt的LIS最小or大的结尾数字 //显然,back为 单调递增or递减 所以可以使用二分查找 int find(int l,int r,int d){ while(l<r){ int mid=(l+r)…
LIS:最长上升子序列: 这个题我们很显然会想到使用dp, 状态设计:dp[i]代表以a[i]结尾的LIS的长度 状态转移:dp[i]=max(dp[i], dp[j]+1) (0<=j< i, a[j]< a[i]) 边界处理:dp[i]=1 (0<=j< n) 时间复杂度:O(N^2)  #include<bits/stdc++.h> using namespace std; inline int read() { ,f=; char ch=getchar()…
/*此题为一个女大佬教我的,%%%%%%%%%%%%*/ 题目描述 给出1-n的两个排列P1和P2,求它们的最长公共子序列. 输入输出格式 输入格式: 第一行是一个数n, 接下来两行,每行为n个数,为自然数1-n的一个排列. 输出格式: 一个数,即最长公共子序列的长度 朴素版的lis是O(N ^ 2)的做法,这里就不在给出:当数据大时很容易被卡,通过二分优化 + 贪心可以优化成为O(NlogN),首先介绍两个函数: lower_bound( )和upper_bound( )是利用二分查找的方法在…
http://poj.org/problem?id=3903 Stock Exchange Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5983   Accepted: 2096 Description The world financial crisis is quite a subject. Some people are more relaxed while others are quite anxious. J…
题目链接: acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 28755    Accepted Submission(s): 8149 Problem Description…
http://acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Problem Description   JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines.Half of these cities are…
给出一个长度为N的无序数组,数组中的元素为整数,有正有负包括0,并互不相等.从中找出所有和 = 0的3个数的组合.如果没有这样的组合,输出No Solution.如果有多个,按照3个数中最小的数从小到大排序,如果最小的数相等则按照第二小的数排序.Input第1行,1个数N,N为数组的长度(0 <= N <= 1000)第2 - N + 1行:A[i](-10^9 <= A[i] <= 10^9)Output如果没有符合条件的组合,输出No Solution.如果有多个,按照3个数中…
[pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=61560361 向大(hei)佬(e)实力学(di)习(tou) Description 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上升子序列长度是多少? Input 第一行一个整数N,表示我们要将1到N插入序列中,接下是N个数字,第k个数字Xk,表示我们将k插入到位…
题目描述 给你n种硬币,知道每种的面值Ai和每种的数量Ci.问能凑出多少种不大于m的面值. 输入 有多组数据,每一组第一行有两个整数 n(1≤n≤100)和m(m≤100000),第二行有2n个整数,即面值A1,A2,A3,…,An和数量C1,C2,C3,…,Cn (1≤Ai≤100000,1≤Ci≤1000).所有数据结束以2个0表示. 输出 每组数据输出一行答案. 样例输入 3 10 1 2 4 2 1 1 2 5 1 4 2 1 0 0 样例输出 8 4 背包问题的复杂度是n*m,这题如果…
Problem Description Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could…