bzoj2044: three-dimensional missile interception

Source: Internet
Author: User

Descriptiona war is unfolding in full swing between country A and State B. State B, with its strong economic power, has developed countless long-range missile missiles, and the leaders of State B hope that they will destroy the command of country a directly and thus win the battle! Of course, the people of country A will not allow such a thing to happen, so there is still an interception missile in the world. You are now a senior assistant to missile interception in country A. B-State missiles effectively formed three-dimensional strikes, we can abstract the position of these missiles three-dimensional intermediate points (size ignore), for the sake of simplicity, we only consider a transient state, that is, their static state. The interceptor missile is well designed to detonate the opposing missile with precision and without loss of its own, but a technical problem facing country A is that these missiles only know how to go straight up. To be precise, the straight rise here refers to the monotonically rising of XYZ three-dimensional coordinates. To all B-country missiles according to the 1 to n marking, an interceptor missile can be struck by a sequence of Strictly monotonically ascending xyz, for example: B State Missile Position: (0, 0, 0) (1, 1, 0) (1, 1, 1), (2, 2, 2) a valid strike sequence is: {1, 3, 4} An illegal strike sequence for {1, 2, 4} A country leaders gave you a list of missile positions and presented you with two of the simplest questions (pretend it's The simplest): 1. How many B-state missiles can a interceptor missile destroy? 2. How many interceptor missiles can be used at least to destroy all missiles in country B? Whether for personal honor or the country is easy, more is for the rice bowl, you, should be good to solve this problem! Inputthe first line an integer n gives the number of missiles in State B. Next n rows of three non-negative integer XI, Yi, Zi give a missile position, you can assume that any two missiles will not appear in the same position. OutputThe first line outputs an integer p, which indicates how many missiles can be destroyed by an interceptor missile. The second line outputs an integer q, which indicates the minimum number of interceptor missiles required. The first question can be topological sort after DP to find the longest chain, the second question minimum path coverage = Longest anti-chain
#include <cstdio>#include<algorithm>intN;intf[1010],ans=0;intes[1000010],enx[1000010],e0[ .],ed[ .],nx[ .],now=1, ep=2;voidMAXS (int&a,intb) {if(a<b) a=b;}structpos{intX, Y, Z;} ps[1010];BOOLCMP (POS A,pos b) {returna.x<b.x;}BOOL operator< (POS A,pos b) {returna.x<b.x&&a.y<b.y&&a.z<b.z;};voidAdde (intAintb) {ES[EP]=b;enx[ep]=e0[a];e0[a]=ep++; ES[EP]=a;enx[ep]=e0[b];e0[b]=ep++;}BOOLDfsintW) {Ed[w]=Now ; if(Nx[w]&&ed[nx[w]]!=now)returnDFS (nx[w]);  for(intI=e0[w];i;i=Enx[i]) {        intu=Es[i]; if(Ed[u]==now)Continue; if(!nx[u]| |dfs (U)) {Nx[w]=u;nx[u]=W; return 1; }    }    return 0;}intMain () {scanf ("%d",&N);  for(intI=0; i<n;i++) scanf ("%d%d%d",&ps[i].x,&ps[i].y,&ps[i].z); Std::sort (Ps,ps+n,cmp);  for(intI=0; i<n;i++) {F[i]=1;  for(intj=0; j<i;j++)if(ps[j]<Ps[i]) {maxs (F[i],f[j]+1); Adde (I,j+N);    } maxs (Ans,f[i]); } printf ("%d\n", ans); Ans=N;  for(intI=1; i<=n;i++,now++)if(!nx[i]) ans-=DFS (i); printf ("%d\n", ans); return 0;}

bzoj2044: three-dimensional missile interception

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.