Dag transfer, from the point of view is a water problem, give you n rods, large can continue small, ask the number of the minimum ascending subsequence.
In fact, the problem is to write with greed, because this is a non-circular map, to reach the fork, each road to the calendar, so each road should be the same treatment, there are two-dimensional restrictions, you can first on one of the dimensions of the order, and then according to the second dimension of the situation to deal with.
For loop:
#include <cstdio>#include<algorithm>#include<cmath>#include<iostream>#include<cstring>using namespacestd;intN;structnode{intU,v;} big[5005];BOOLvis[5005];BOOLCMP (node A,node b) {if(a.u<b.u)return 1; Else if(a.u==b.u&&a.v<B.V)return 1; return 0;}intMain () {//freopen ("Input.txt", "R", stdin); intCAs; CIN>>CAs; while(cas--) {cin>>O; for(intI=0; i<n;i++) {cin>>big[i].u>>big[i].v; } sort (Big,big+n,cmp); intans=0; intt=0; memset (Vis,0,sizeof(VIS)); for(intI=0; i<n;i++) { if(Vis[i])Continue; Vis[i]=1; T=big[i].v; Ans++; for(intj=i+1; j<n;j++) { if(big[j].v>=t&&vis[j]==0) {T=big[j].v; VIS[J]=1; }}} printf ("%d\n", ans); }}
Memory of Dfs greedy:
#include <cstdio>#include<algorithm>#include<cmath>#include<iostream>#include<cstring>using namespacestd;intN;structnode{intU,v;} big[5005];BOOLvis[5005];BOOLCMP (node A,node b) {if(a.u<b.u)return 1; Else if(a.u==b.u&&a.v<B.V)return 1; return 0;}voidDfsintx) { if(Vis[x])return; VIS[X]=1; for(intj=x+1; j<n;j++) { if(vis[j]==0&&big[j].v>=big[x].v) {DFS (j); Break;//when the memory of greed to add break; } }}intMain () {//freopen ("Input.txt", "R", stdin); intCAs; CIN>>CAs; while(cas--) {cin>>N; for(intI=0; i<n;i++) {cin>>big[i].u>>big[i].v; } sort (Big,big+n,cmp); intans=0; memset (Vis,0,sizeof(VIS)); for(intI=0; i<n;i++) { if(!Vis[i]) {DFS (i); Ans++; }} printf ("%d\n", ans); }}
zoj1025 Wooden Sticks