This problem is the deep search matrix, and then quickly power.
1#include <iostream>2#include <cstring>3#include <cstdio>4#include <map>5 using namespacestd;6 Const intmaxn= $;7 Const intMod=65521;8 structmatrix{9 Long LongMAT[MAXN][MAXN];Ten intr,c; OneMatrix (intr_=0,intc_=0,inton=0){ AMemset (Mat,0,sizeof(MAT)); -R=r_;c=c_; - if(ON) for(intI=1; i<=r;i++) mat[i][i]=1; the } -Matrixoperator*(Matrix a) { - Matrix ret (R,A.C); - Long Longl; + for(intI=1; i<=r;i++) - for(intk=1; k<=c;k++){ +L=Mat[i][k]; A for(intj=1; j<=a.c;j++) at(ret.mat[i][j]+= (L*a.mat[k][j])%mod)%=MoD; - } - returnret; - } -Matrixoperator^(Long Longk) { -Matrix ret (R,c,1), X (r,c); in for(intI=1; i<=r;i++) - for(intj=1; j<=c;j++) tox.mat[i][j]=Mat[i][j]; + while(k) { - if(k&1) theret=ret*x; *k>>=1; $x=x*x;Panax Notoginseng } - returnret; the } + }a,b; A the Long LongN; +map<int,int>ID; -map<int,BOOL>used; $ intk,e,e1,e[maxn][2]; $ intcnt,st[1<< -],mem[1<< -]; - intFA[MAXN],SZ[MAXN],VIS[MAXN]; - intFind (intx) { the returnx==fa[x]?x:fa[x]=Find (fa[x]); - }Wuyi BOOLCheck (ints) { the for(intI=1; i<maxn;i++) -fa[i]=i,sz[i]=1; Wu for(intI=0; i<e+e1;i++) - if(s& (1<<i)) { About intU=find (e[i][0]), V=find (e[i][1]); $ if(U!=V) {fa[u]=v;sz[v]+=sz[u];} - Else return false; - } - return true; A } + the voidSolve (intx) { - for(intI=1; i<=x;i++) $ for(intj=i+1; j<=x;j++) thee[e][0]=i,e[e][1]=j,e++; the for(intI=1; i<=x;i++) thee[e+e1][0]=i,e[e+e1][1]=x+1, e1++; the - for(intS= (1<<e)-1, num;s>=0; s--) in if(Check (s)) { thememset (Vis,0,sizeof(VIS)); num=0; the for(intI=1; i<=x;i++){ About if(Vis[find (i)])Continue; theVis[find (i)]=++num; the } thenum=0; + for(intI=1; i<=x;i++) -num=num*Ten+Vis[find (i)]; the if(Id[num]) b.mat[id[num]][1]+=1;Bayi Else{ thea.r+=1; a.c+=1; b.r+=1; theb.mat[id[num]=b.r][1]=1; -st[++cnt]=s;mem[cnt]=num; - } the } the the for(intt=1, s;t<=cnt;t++){ the for(intP= (1<<E1)-1, num;p>=0;p--){ -s=st[t]^ (p<<e); the if(Check (s) &&sz[find (1)]!=1){ thememset (Vis,0,sizeof(VIS)); num=0; the for(intI=2; i<=x+1; i++){94 if(Vis[find (i)])Continue; theVis[find (i)]=++num; the } thenum=0;98 for(intI=2; i<=x+1; i++) Aboutnum=num*Ten+Vis[find (i)]; -a.mat[id[num]][id[mem[t]]]+=1;101 }102 }103 }104 return; the }106 107 intMain () {108 #ifndef Online_judge109Freopen ("count.in","R", stdin); theFreopen ("Count.out","W", stdout);111 #endif thescanf"%d%lld",&k,&n);113K=min (1ll*k,n); Solve (k); B.c=1; thea=a^ ((n-k)% (1ll* (mod+1) * (mod-1))); b=a*B; theprintf"%lld\n", b.mat[1][1]); the return 0;117}
Linear algebra (Matrix multiplication): NOI 2007 Spanning Tree Count