zoukankan      html  css  js  c++  java
  • bzoj1046 [HAOI2007]上升序列

    题意

    对于一个给定的(S={a1,a2,a3,…,an}),若有(P={ax1,ax2,ax3,…,axm}),满足((x1 < x2 < … < xm))且((ax1 < ax 2 < … < axm))。那么就称P为S的一个上升序列。如果有多个P满足条件,那么我们想求字典序最小的那个。任务给出(S)序列,给出若干询问。对于第i个询问,求出长度为Li的上升序列,如有多个,求出字典序最小的那个(即首先(x1)最小,如果不唯一,再看(x2)最小……),如果不存在长度为(Li)的上升序列,则打印Impossible.

    题解

    傻逼题。LIS搞。输出贪心。
    其实这份代码会PE

    #include<set>
    #include<queue>
    #include<cstdio>
    #include<vector>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    
    inline int read() {
    	int x = 0, flag = 1; char ch = getchar();
    	while (ch > '9' || ch < '0') { if (ch == '-') flag = -1; ch = getchar(); }
    	while (ch <= '9' && ch >= '0') { x = x * 10 + ch - '0'; ch = getchar(); }
    	return x * flag;
    }
    
    #define rep(ii, aa, bb) for (int ii = aa; ii <= bb; ii++)
    #define drp(ii, aa, bb) for (int ii = aa; ii >= bb; ii--)
    #define ll long long
    #define N 10001
    
    int a[N], f[N];
    
    int main() {
    	int n = read(), maxL = 1;
    	rep(i, 1, n) a[i] = read(), f[i] = 1;
    	drp(i, n, 1) drp(j, n, i + 1) if (a[j] > a[i]) maxL = max(maxL, (f[i] = max(f[i], f[j] + 1)));
    	int q = read();
    	while (q--) {
    		int L = read();
    		if (L > maxL) { puts("Impossible
    "); continue; }
    		int mn = 0;
    		rep(i, 1, n) if (f[i] >= L && a[i] > mn) {
    			printf("%d", a[i]); if (L != 1) printf(" ");
    			mn = a[i];  if (--L == 0) break;
    		}
    		printf("
    ");
    	}
    	return 0;
    }
    
  • 相关阅读:
    weak_ptr解决shared_ptr环状引用所引起的内存泄漏[转]
    如何限制对象只能建立在堆上或者栈上(转载)
    为了异常安全(swap,share_ptr)——Effecive C++
    注意类型转换——Effective C++
    http协议
    【java.math.BigInteger】常用函数
    【java.math.BigInteger】【转】常见问题
    【思路,dp,BigInteger】ZOJ
    【Warshall_Floyd】
    【Dijkstra】
  • 原文地址:https://www.cnblogs.com/aziint/p/8416130.html
Copyright © 2011-2022 走看看