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;
    }
    
  • 相关阅读:
    前言(CSDN也有Markdown了,好开森)
    One usage of recurison: the tower of Hanoi
    使用Android注解来改善代码
    mysql生产环境____主从同步修复案例
    不同类型的指针
    C++ 对象模型
    为什么需要模版成员方法
    理解 traits
    C++ 异常处理
    传const引用代替传值
  • 原文地址:https://www.cnblogs.com/aziint/p/8416130.html
Copyright © 2011-2022 走看看