#include #include #include #include #include #include // #include using namespace std; typedef long long LL; typedef pair SufType; const int maxn=1005; int N,K,a[maxn]; bool used[maxn]; vector position,number; LL OuterPair[20][20],stk[20],Answer,TotalNotFixed,InnerPair[1<<14][20]; int hsh[(1<<14)+1]; int PreLength,SufLength; struct Hash_SufType2LongLong { const static int PoolSize=17297280*3; const static LL a=233331,b=19260817; LL Pool[PoolSize]; int head[PoolSize],nxt[PoolSize],stv[PoolSize],CntV[PoolSize],PoolCnt=0; inline LL& operator[](const SufType &key) { const LL HashValue=(key.first*a+key.second+b)%PoolSize; // return Pool[HashValue]; int p=head[HashValue]; while(p) { if(stv[p]==key.first&&CntV[p]==key.second) return Pool[p]; p=nxt[p]; } PoolCnt++; nxt[PoolCnt]=head[HashValue]; stv[PoolCnt]=key.first; CntV[PoolCnt]=key.second; head[HashValue]=PoolCnt; return Pool[PoolCnt]; } }SufData; void dfs(int dep,LL CurrentPair,int st) { if(dep==PreLength) { Answer+=SufData[SufType(((1<CurrentPair+(TotalNotFixed-dep)*(TotalNotFixed-dep-1)/2+(TotalNotFixed-dep)*(N-TotalNotFixed+dep))) { stk[dep]=number[i]; dfs(dep+1,CurrentPair+InnerPair[st][i]+OuterPair[dep][i],st|(1<a[j]) AlreadyHave++; for(int i=1;i<=N;i++) if(!used[i]) number.push_back(i); TotalNotFixed=position.size(); for(int i=0;inum)||(a[k]!=0&&k>pos&&a[k]number[p]) InnerPair[st][p]++; if(K>AlreadyHave+TotalNotFixed*(TotalNotFixed-1)/2+TotalNotFixed*(N-TotalNotFixed)) { puts("0"); return 0; } for(int i=0;i