"Problem description"
There is a piece of pseudo-code that uses a bubbling sort to produce a graph as follows:
function Bubblesortgraph (n, a[]):
Graph = Emptygraph ()
Repeat
Swapped = False
For i = 1 to n-1:
If a[i] > a[i + 1]:
Graph.addedge (A[i], a[i + 1])
Swap (A[i], a[i + 1])
swapped = True
Until not swapped
Return graph
The input of the function is the arrangement of the length? [], the output is a single node of the non-direction diagram. function,
Emptygraph () Creates an empty graph, Addedge (x, y) adds an x to the graph.
And Y, the last graph that is returned is the non-direction graph.
The point independent set of graphs is a subset of the node collections in the graph. If the collection is a point-independent set of graphs,
So, any of the two nodes in the graph are not connected directly to each other.
Given an arrangement of 1~, request a large independent set of maximum points of the non-graph generated by pseudo-code
Small, and must be present in the node with the largest point independent concentration.
"Input Format"
Enter the first line containing an integer?. The next line contains a space-delimited integer that represents the order
Column? []。
"Output Format"
Outputs two lines. The first line contains an integer that represents the size of the maximum point independent set of the generated graph.
The second line outputs the maximum point in a separate set of nodes that must contain the corresponding subscript in the input sequence, according to the
Small to large sequential outputs, separated by spaces.
"Sample Input"
3
3 1 2
"Sample Output"
2
2 3
"Data size and conventions"
60% of the data,? ≤1000.
For 100% of data, 1≤? ≤100,000.
Prompted
The number of nodes that must exist in the maximum point independent set does not necessarily equal the size of the maximum point independent sets
/*The analysis can be drawn that this is the longest ascending subsequence. Analysis: Bubble sort, when i<j&&a[i]<a[j], the two will not be exchanged, will not build the edge, the other side of the building. Practice: First ask very well, focus on the second question. The first time to do is written in 60 points (but also written off), for the two elements without building edges, give them an edge, and then search for the total number of the longest ascending subsequence, each element of which is marked, if an element is marked and the longest ascending subsequence number equal, then output. Positive solution: loop backwards again, if there is an element behind it that is larger than it is in the longest ascending sub-sequence, it must also be in the longest ascending subsequence. And the record length of I in the longest ascending subsequence sequence segment has several. Finally counts which elements in the longest ascending subsequence and its that length appeared only once. */#include<cstdio>#include<iostream>#include<algorithm>#defineN 100010using namespacestd;intA[n],q[n],f[n],maxx[n],ok[n],sum[n],n;intMain () { //freopen ("bubble.in", "R", stdin); //freopen ("Bubble.out", "w", stdout);scanf"%d",&N); for(intI=1; i<=n;i++) {scanf ("%d",&A[i]); } q[1]=a[1];f[1]=1;intlen=1; for(intI=2; i<=n;i++){ intPos=lower_bound (q+1, q+len+1, A[i])-Q; if(pos>Len) {F[i]=len+1; q[++len]=A[i]; } Else{F[i]=pos;q[pos]=A[i]; }} printf ("%d\n", Len); Maxx[len+1]=N; for(inti=n;i>=1; i--){ if(maxx[f[i]+1]>A[i]) {Ok[i]=true; sum[f[i]]++; Maxx[f[i]]=Max (maxx[f[i]],a[i]); } } for(intI=1; i<=n;i++){ if(ok[i]&&sum[f[i]]==1) printf ("%d", i); } return 0;}
Bubble Sort Chart