1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#define X first #define Y second using namespace std; const int Maxn=50000; const int INF=0x3f3f3f3f; typedef pair<int,int> pii; typedef long long ll; int n,a[Maxn],dp[Maxn],nex[Maxn]; int () { int T; scanf("%d",&T); while(T--) { scanf("%d",&n);a[0]=0,dp[0]=0; for(int i=1;i<=n;i++) scanf("%d",&a[i]),dp[i]=0,nex[i]=-1; for(int i=n;i>=0;i--) { for(int j=i+1;j<=n;j++) if(a[i] < a[j]) { if(dp[i] < dp[j]+1 || dp[i]==dp[j]+1 && a[nex[i]] > a[j]) { dp[i] = dp[j]+1; nex[i] = j; } } } printf("%d ",dp[0]); int dex=nex[0]; while(dex!=-1) { printf("%d ",a[dex]); dex=nex[dex]; } puts(""); } return 0; }
|
近期评论