Topic links
Enumerate pairs, enumerate each card, first out of its inscription, the rest of the straight. \ (O (n^3) \).
Not so----out of all the inscriptions, and finally the straight. (Daily ZZ)
The first three of the same, and then shun son, once and must use a chance to fill the empty space, that is, to replace the engraved pair. This seems to be \ (O (n^2) \).
Do not write \ (O (n^2) \) , the special sentence is probably very troublesome.
//828kb 396ms#include <cstdio>#include <cctype>#include <cstring>#define GC () GetChar ()Const intn=407;intN,m,tot,tmp[n],num[n],ans[n];inline intRead () {intnow=0;Register CharC=GC (); for(;! IsDigit (c); C=GC ()); for(; IsDigit (c); now=now*Ten+c-' 0 ', C=GC ());returnNow;}BOOLCheck () { for(intI=1; I<=n+2; ++i)//Finish processing the front before processing this one! if((num[i]%=3) >0) num[i+1]-=num[i], Num[i+2]-=num[i], num[i]=0;//directly to lose the line, what Else if(num[i]<0)return 0;return 1;}intMain () {N=read (), M=read (), tot=3*m+1; for(intI=1; i<=tot; ++i) ++tmp[read ()];intCnt=0; for(intI=1; i<=n; ++i) {++tmp[i]; for(intj=1; j<=n; ++J)if(tmp[j]>=2) {tmp[j]-=2, memcpy (Num,tmp,sizeofNUM), tmp[j]+=2;if(Check ()) {ans[++cnt]=i; Break;} }--tmp[i]; }if(CNT) for(intI=1; i<=cnt; ++i) printf ("%d ", Ans[i]);ElsePuts"NO");return 0;}
bzoj.1028. [JSOI2007] Mahjong (greedy)