Dolls-4160 (simple binary graph matching)

Source: Internet
Author: User

Test instructions: There are some boxes, large boxes can be small boxes, but must h>h,w>w,l>l, to find out the outermost can be left a few boxes cannot be nested.   Analysis: Thinking of each box will only be another box, so make up one or two points matching model, only need to find the biggest match, because there is no match can not be nested, has been matched to find nested its box, the result is the total number of boxes-the maximum match. The code is as follows:=========================================================================================================== ============================
#include <stdio.h>#include<string.h>Const intMAXN =507;Const intOO = 1e9+7;structpoint{intWI, Li, hi;} P[MAXN];intG[MAXN][MAXN], LY[MAXN], N;BOOLUSED[MAXN];BOOLOK (Point A, point B) {if(A.hi<b.hi && a.li<b.li && a.wi<b.wi)return true; return false;}BOOLFind (inti) {     for(intj=1; j<=n; J + +)    {        if(!used[j] &&G[i][j]) {Used[j]=true; if(! LY[J] | |Find (Ly[j])) {Ly[j]=i; return true; }        }    }    return false;}intXYL () {memset (Ly,0,sizeof(Ly)); intAns =0;  for(intI=1; i<=n; i++) {memset (used,false,sizeof(used)); if(Find (i) = =true) ans++; }    returnans;}intMain () { while(SCANF ("%d", &N), N) {intI, J; memset (G,0,sizeof(G));  for(i=1; i<=n; i++) scanf ("%d%d%d", &p[i].wi, &p[i].li, &P[i].hi);  for(i=1; i<=n; i++)         for(j=1; j<=n; J + +)        {            if(OK (P[i], p[j]) = =true) G[i][j]=1; } printf ("%d\n", N-XYL ()); }    return 0;}

Dolls-4160 (simple binary graph matching)

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.