Test Instructions:
n equipment, two attributes, the value of the property in the range of 1~10000, encountered a boss, need to use a continuous increment of the value of the property from 1 to attack, and one device can only be used once, ask the maximum number of hits.
parsing:
The best match for a classic binary chart?
The property value matches the first few.
So the direct map to run the maximum match can be.
But this one, every time we clear the array, it doesn't work--
is also the card I quite long time, also thought the binary chart biggest match too, later read the topic explanation with the time stamp, too God too God also has such fun thing--how I did not know.
Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 1000100using namespace STD;intv[n<<1];intmatch[n<<1];inthead[n<<1];intCntintNintNowtime;structnode{intFrom,to,next;} edge[n<<1];voidInit () {memset(head,-1,sizeof(head)); Cnt=1;}voidEdgeadd (intFromintTo) {Edge[cnt].from=from,edge[cnt].to=to,edge[cnt].next=head[from]; head[from]=cnt++;}BOOLFindintx) { for(inti=head[x];i!=-1; i=edge[i].next) {intto=edge[i].to;if(V[to]!=nowtime) {v[to]=nowtime;if(!match[to]| | Find (Match[to])) {match[to]=x;return 1; } } }return 0;}intMain () {init ();scanf("%d", &n); for(intI=1; i<=n;i++) {intx, y;scanf("%d%d", &x,&y); Edgeadd (X,i), Edgeadd (y,i); } for(intI=1; i<=n;i++) {nowtime++;if(!find (i)) {printf("%d\n", I-1);return 0; } }printf("%d\n", n);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Bzoj 1854 [Scoi2010] game binary graph Max match