CodeForces - 846A Curriculum Vitae LIS(最长上升子序列)n logn
2017-09-07 21:50
459 查看
教育场,当真是叫人受教育
此场 1 题滚出
这个 A 题也是很傻逼,可能是因为最近做题不够,思考不够
这个题显然的是求 最长上升子序列
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <ctype.h>
#include <vector>
#include <algorithm>
#include <sstream>
#define PI acos(-1.0)
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
using namespace std;
typedef long long ll;
const int maxn = 100 + 7, INF = 0x3f3f3f3f, mod = 1e9 + 7;
int n;
int a[maxn];
int b[maxn];
int main() {
scanf("%d", &n);
int x;
for(int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
memset(b, INF, sizeof b);
for(int i = 0; i < n; ++i) {
*upper_bound(b, b+maxn, a[i]) = a[i];
}
int ans = lower_bound(b, b+maxn, INF) - b;
cout << ans << endl;
return 0;
}
此场 1 题滚出
这个 A 题也是很傻逼,可能是因为最近做题不够,思考不够
这个题显然的是求 最长上升子序列
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <ctype.h>
#include <vector>
#include <algorithm>
#include <sstream>
#define PI acos(-1.0)
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
using namespace std;
typedef long long ll;
const int maxn = 100 + 7, INF = 0x3f3f3f3f, mod = 1e9 + 7;
int n;
int a[maxn];
int b[maxn];
int main() {
scanf("%d", &n);
int x;
for(int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
memset(b, INF, sizeof b);
for(int i = 0; i < n; ++i) {
*upper_bound(b, b+maxn, a[i]) = a[i];
}
int ans = lower_bound(b, b+maxn, INF) - b;
cout << ans << endl;
return 0;
}
相关文章推荐
- 最长上升子序列LIS
- CodeForces 10D. LCIS 最长公共上升子序列模板题 + 打印路径
- 【POJ2533】Longest Ordered Subsequence(LIS-最长上升子序列/DP)
- hdu5773(2016多校第四场,最长上升子序列n*logn变形)
- 关于最长上升子序列的问题(LIS)
- Stock Exchange(最长上升子序列LIS)
- LIS 模板 (最长上升/下降子序列) STL实现
- 最长上升子序列LIS(云笔记图片版)
- 最长上升子序列LIS
- LIS最长上升子序列(打印路径)
- DP LIS(最长上升子序列) POJ 2533 POJ 1836 POJ 2138 HDU 1069
- LIS(最长上升子序列两种算法模板)DP模板,并且输出序列
- 最长上升子序列模板(LIS)
- LIS(最长上升子序列)
- lis求最长上升子序列问题
- 算法练习--- DP 求解最长上升子序列(LIS)
- 动态规划-最长上升子序列LIS
- Codeforces 490F Treeland Tour 树上的最长上升子序列
- hdu 5256 序列变换(LIS最长上升子序列)
- LIS 最长上升子序列N^2以及nlogn算法