Transmission Door
Search Package The second iteration deepens
Compared to the classic because of his search layer in time and space is unknown
So we can give him a predetermined number of layers to search for.
If there is no optimal solution at this level
Then jump to the next level and search.
For each layer of search attention pruning
First is the feasibility of pruning for this number if the number is greater than the desired so t drop the point
If the number multiplied by three is less than the desired t-drop point
Pay attention to the properties of fractions note-Pass
Note the requirement of minimum dictionary order
Spit it out, the data is slightly weak.
Below is a slightly slower AC code to optimize
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace STD;Long Longs[ -],ans[ -],sr,ar;structscore{Long LongUp,down; Score () {} score (Long LongXLong LongY): Up (x), X=X/__GCD (y) {x, y), y=y/__gcd (x, y);}DoubleCalc () {return 1.0*up/down;}}; Scoreoperator-(score A,score B) {Long LongTmp1=a.up,tmp2=a.down,tmp3=b.up,tmp4=b.down; Tmp1*=tmp4,tmp3*=tmp2;tmp1-=tmp3; Tmp2*=tmp4;Long LongK=__GCD (TMP1,TMP2); Tmp1/=k,tmp2/=k; Score C (TMP1,TMP2);returnC;}BOOL operator< (score A,score B) {returnA.calc () < B.calc ();} Scoreoperator*(intX,score B) {score C (B.up*x,b.down);returnC;}intTotBOOLcmp=false;voidCheck () {Long LongTmp1=sr,tmp2=ar;if(!ar) { for(intI=1; i<=sr;++i) ANS[I]=S[I];AR=SR;return;}if(S[TMP1]>ANS[TMP2])return;if(S[TMP1]<ANS[TMP1]) { for(intI=1; i<=sr;++i) ans[i]=s[i];return;} tmp1=1; while(ANS[TMP1]==S[TMP1]) tmp1++;if(ANS[TMP1]>S[TMP1]) for(intI=tmp1;i<=sr;++i) ans[i]=s[i];}voidPut () { for(intI=1; i<ar;++i)printf("%lld", Ans[i]);printf("%lld", Ans[ar]);}voidDFS (Score A,intDepthintXintwould) {if(Depth >= would) {if(a.up==1) {S[++sr]=x;s[++sr]=a.down;if(s[sr]==s[sr-1]) {sr-=2;return;} Check (); sr-=2; cmp=true;}return;}if(1.0* (will-depth+1)/x<a.calc ())return;Doubletmp=1.0* (will-depth+1)/a.calc (); for(inti=x+1; tmp>i;++i) {Score C (1, i);if(A<C)Continue; Score tmp (1, i); Score b=a-tmp;if(depth>1) S[++sr]=x; DFS (b,depth+1, I,will);if(depth>1)--SR; }}intMain () {intb;Cin>>a>>b; Score A (A, b);intCNT =0; while(1) {cnt++; DFS (A,1,1, CNT);if(CMP) {put ();return 0;} } }
Egypt score IDS Search Vijos 1308