Greed is a soft rib ...
Do a good brush on the problem.
Or we're going to blow up tomorrow.
Let's all be greedy today.
Well!
Or the sort of a struct. (this thing is really useful!) )
Sort lengths from small to large
If the length is equal then the weight is small in front
Select the first node is not an initial node
Then scan the side array
See those nodes can be processed without processing time
Mark it well.
And then in sequential scan side array
Find the first node without a tag
Do the same scan again.
Loop in turn
See how many times you finish
That is the time of processing
So this sort really is the essence!
I can only say that the knees are rotten ...
L and W mean the opposite, W is the length, L is the weight. #include <iostream> #include <algorithm> #include <stdio.h>using namespace std;struct wood{int w;int l ;} A[5001];bool CMP (wood A,wood b) {//if (A.W = = B.W)//return a.l < b.l;//same length, small weight in front//else// return A.W < b.w;
return A.w==b.w?a.l < B.L:A.W < B.W;} the int main () {int d[5001];//is used to record the starting point int t,n,ans,i,j;scanf ("%d", &t) of the different sequences, while (t--) {scanf ("%d", &n), and for (i=0;i <n;i++) scanf ("%d%d", &A[I].W,&A[I].L), sort (a,a+n,cmp), or//length first in ascending order, where the weight conflicts will be rescheduled ans = 1;d[0] = a[0].l;/ /first set the first to start for (i=1;i<n;i++) {for (j=0;j<ans;j++) {if (a[i].l >= d[j])//Can be in the back, update {d[j] = A[I].L; Break;}} if (J==ans)//All starting point does not work, then re-arrange from here a starting point {if (A[i].l < d[j-1]) {d[j] = A[I].L; Ans + +;}}} printf ("%d\n", ans);}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ 1065:wooden Sticks