bzoj1046: [HAOI2007]上升序列
真尼玛神坑
m还可以等于0
mgj
1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<algorithm> 5 #include<iostream> 6 7 using namespace std; 8 9 void setIO(const string& s) { 10 freopen((s + ".in").c_str(), "r", stdin); 11 freopen((s + ".out").c_str(), "w", stdout); 12 } 13 template<typename Q> Q read(Q& x) { 14 static char c, f; 15 for(f = 0; c = getchar(), !isdigit(c); ) if(c == '-') f = 1; 16 for(x = 0; isdigit(c); c = getchar()) x = x * 10 + c - '0'; 17 if(f) x = -x; 18 return x; 19 } 20 template<typename Q> Q read() { 21 static Q x; read(x); return x; 22 } 23 24 const int N = 10000 + 10, INF = ~0u >> 1; 25 int a[N], s[N], f[N]; 26 27 int main() { 28 #ifdef DEBUG 29 freopen("in.txt", "r", stdin); 30 freopen("out.txt", "w", stdout); 31 #endif 32 33 int n, m; read(n); 34 for(int i = 1; i <= n; i++) read(a[i]), a[i] = -a[i]; 35 memset(s, 0x7f, sizeof s); 36 for(int i = n; i >= 1; i--) { 37 int t = lower_bound(s + 1, s + n + 1, a[i]) - s; 38 f[i] = t; 39 s[t] = a[i]; 40 } 41 read(m); 42 while(m--) { 43 int r = read<int>(), last = INF; 44 if(!r) puts(""); 45 else { 46 for(int i = 1; r && i <= n; i++) { 47 if(f[i] >= r && a[i] < last) last = a[i], printf("%d%c", -a[i], (!--r) ? '\n' : ' '); 48 } 49 if(r) puts("Impossible"); 50 } 51 } 52 53 return 0; 54 }
原文出处http://www.cnblogs.com/showson/