提交时间:2024-02-26 13:34:49
运行 ID: 26788
#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define m_p make_pair #define p1 first #define p2 second #define p_b push_back using namespace std; typedef long long ll; const int maxn=1e5+10,mod=998244353; inline ll read(){ ll x=0;short t=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; }int n,k,CT,ID;bool ff; int f[10][10],vis[10]; ll dp[maxn]; ll qpow(int a,ll b){ ll res=1; while(b){ if(b&1)res=res*1ll*a%mod; a=a*1ll*a%mod;b>>=1; }return res; } ll jc(int x){ ll res=1; up(i,1,x)res=res*1ll*i%mod; return res; } void dfs(int u,int ct){ if(u==ID&&vis[u]){ if(ct==k)ff=1; return; }if(vis[u])return; vis[u]=1; up(i,1,n)if(i!=u&&f[u][i])dfs(i,ct+1); vis[u]=0; } void DFS(int x,int y){ if(y>n)x++,y=x+1; if(x==n){ ff=0; up(i,1,n){ if(ff)break; ID=i; dfs(i,0); }if(ff)CT++; return; }f[x][y]=0,f[y][x]=1; DFS(x,y+1); f[x][y]=1,f[y][x]=0;DFS(x,y+1); } void slv(){ n=read(),k=read(); if(k==3){ printf("%d\n",(qpow(2,n*1ll*(n-1)/2)-jc(n)+mod)%mod); return; } DFS(1,2); printf("%d\n",CT); }int main(){ // freopen("tournament.in","r",stdin); // freopen("tournament.out","w",stdout); slv(); fclose(stdin); fclose(stdout); return 0; }