What Goes Up UVA - 481 LIS+打印路径 【模板】
打印严格上升子序列;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<time.h>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 200005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
#define mclr(x,a) memset((x),a,sizeof(x))
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 9999973;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-5
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii; inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/
int n;
int a[maxn];
int pos[maxn];
int dp[maxn];
int lst[maxn]; int main()
{
// ios::sync_with_stdio(0);
int x;// n = rd();
n = 0;
while (cin >> x) {
n++; a[n] = x;
}
int len = 1, po = 1;
dp[1] = a[1]; pos[1] = 1;
for (int i = 2; i <= n; i++) {
if (a[i] > dp[len]) {
dp[++len] = a[i]; pos[++po] = len;
}
else {
int ct = lower_bound(dp + 1, dp + len + 1, a[i]) - dp;
dp[ct] = a[i]; pos[++po] = ct;
}
}
cout << len << endl;
puts("-");
int tmp = len;
for (int i = n; i >= 1; i--) {
if (pos[i] == tmp)lst[tmp--] = a[i];
if (tmp < 1)break;
}
for (int i = 1; i <= len; i++)printf("%d\n", lst[i]);
return 0;
}
What Goes Up UVA - 481 LIS+打印路径 【模板】的更多相关文章
- Uva 10131 Is Bigger Smarter? (LIS,打印路径)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=1072">链接:UVa 10131 题意: ...
- Uva 10054 欧拉回路 打印路径
看是否有欧拉回路 有的话打印路径 欧拉回路存在的条件: 如果是有向图的话 1.底图必须是连通图 2.最多有两个点的入度不等于出度 且一个点的入度=出度+1 一个点的入度=出度-1 如果是无向图的话 1 ...
- Floyd 算法 打印路径模板
#include <iostream> #include <cstdlib> #include <cstdio> #include <algorithm> ...
- UVa 103 - Stacking Boxes (LIS,打印路径)
链接:UVa 103 题意:给n维图形,它们的边长是{d1,d2,d3...dn}, 对于两个n维图形,求满足当中一个的全部边长 依照随意顺序都一一相应小于还有一个的边长,这种最长序列的个数,而且打 ...
- UVA 10054 The Necklace(欧拉回路,打印路径)
题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- HDU-1160.FatMouse'sSpeed.(LIS变形 + 路径打印)
本题大意:给定一定数量的数对,每个数保存着一只老鼠的质量和速度,让你求出一个最长序列,这个序列按照质量严格递增,速度严格递减排列,让你输出这个序列的最长长度,并且输出组成这个最长长度的序列的对应的老鼠 ...
- UVA 1626 区间dp、打印路径
uva 紫书例题,这个区间dp最容易错的应该是(S)这种匹配情况,如果不是题目中给了提示我就忽略了,只想着左右分割忘记了这种特殊的例子. dp[i][j]=MIN{dp[i+1][j-1] | if( ...
- uva 116 Unidirectional TSP【号码塔+打印路径】
主题: uva 116 Unidirectional TSP 意甲冠军:给定一个矩阵,当前格儿童值三个方向回格最小值和当前的和,就第一列的最小值并打印路径(同样则去字典序最小的). 分析:刚開始想错了 ...
- UVA 624 (0 1背包 + 打印路径)
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<ctype.h> #i ...
随机推荐
- IE回车的一个怪异行为
IE中在input中回车相当于提交form,会从dom中找最近的button标签触发click事件 <!DOCTYPE html> <html> <head> &l ...
- deeplearning.ai 旁听如何做课后编程作业
在上吴恩达老师的深度学习课程,在coursera上. 我觉得课程绝对值的49刀,但是确实没有额外的钱来上课.而且课程提供了旁听和助学金. 之前在coursera上算法和机器学习都是直接旁听的,这些课旁 ...
- Python将两个数组合并成一个数组,多维数组变成一维数组
1.extend方法 c1 = ["Red","Green","Blue"] c2 = ["Orange"," ...
- oracle使用exp/imp导入导出(用户)
实例,从远程机器上导出nxgy用户的所有对象和数据,然后导入到本机数据库的nxgy用户里(用户名可自定义) 如果本机nxgy用户已经存在(数据没用,可以删除),级联删除用户所有对象 首先,从远程机器上 ...
- 因采用 Flask 原生 WSGI 出现 "Broken pipe" 报错的故障处理
:first-child { margin-top: 0; } blockquote > :last-child { margin-bottom: 0; } img { border: 0; m ...
- yii2 源码分析1从入口开始
我是在 backend 一步步打印的 很多地方我也是很模糊 .后来发现一位大神的文章(http://www.yiichina.com/tutorial/773) 参考文章自己动手开始写的 至于后来的 ...
- Virtual Machine Definition File 2.2
Virtual Machine Definition File 2.2 http://archives.opennebula.org/documentation:archives:rel2.2:tem ...
- fiddler抓包时显示Tunnel to......443
打开手机浏览器,输入http://192.168.0.65:8888/FiddlerRoot.cer
- javascript总结3:javaScript的 Math 对象
Math 对象 Math 对象用于执行数学任务. Math 对象并不像 Date 和 String 那样是对象的类,因此没有构造函数 Math(). Math 常用的方法 var n1=1234; v ...
- 第02章-装配Bean
1. Spring配置的可选方案 在XML中进行显式配置: 在Java中进行显式配置: 隐式的bean发现机制和自动装配. 2. 自动化装配bean Spring从两个角度来实现自动化装配: 组件扫描 ...