#include using namespace std; using ll=long long; struct card{ ll a,b; card(){} card(ll a,ll b):a(a),b(b){} void print(){ cout< v={45,16,12,9,7,5,1}; const ll x=500000000000000000; int n; struct state{ vector chosenindex; double score; vector c; vector> operations; void calc_score(){ score=0; double s=0; for(int i:chosenindex)score+=max(abs(c[i].a-x),abs(c[i].b-x)); score/=chosenindex.size(); for(int i:chosenindex)s+=(max(abs(c[i].a-x),abs(c[i].b-x))-score)*(max(abs(c[i].a-x),abs(c[i].b-x))-score); s/=chosenindex.size(); //score+=s/100000; } state generate(vector& indexes){ state res; res.chosenindex.resize(indexes.size()); res.operations=operations; res.c=c; int t=0; for(int i:indexes){ res.chosenindex[t]=chosenindex[i]; t++; } for(int p:res.chosenindex){ card t=res.c[p]+res.c[(p+1)%n]; int index=(p+1)%n; for(int j=2;jmax(abs(tt.a-x),abs(tt.b-x))){ index=(p+j)%n; t=tt; } } res.c[p]=t; res.c[index]=t; res.operations.push_back(make_pair(p+1,index+1)); } res.calc_score(); return res; } }; bool operator<(state p,state q){ return p.score c){ auto f=[&](int p){ card t=c[p]+c[(p+1)%n]; int index=(p+1)%n; for(int j=2;jmax(abs(tt.a-x),abs(tt.b-x))){ index=(p+j)%n; t=tt; } } c[p]=t; c[index]=t; cout<>n; vector c(n); random_device seed; mt19937 rnd(seed()); for(int i=0;i>a>>b; c[i]=card(a,b); } cout<<50< bc={1,250,200,100,50,30,1}; vector beam(1); state c0; c0.c=c; c0.chosenindex.resize(n); for(int i=0;i new_beam(bc[i]*bc[i+1]); for(int j=0;j indexes; vector vv(v[i+1]); indexes.insert(0); for(int k=0;k+1