康拓展开/逆展开 模板
#include#include #include #define int long longusing namespace std;inline int rd(){ int ret=0,f=1;char c; while(c=getchar(),!isdigit(c))f=c=='-'?-1:1; while(isdigit(c))ret=ret*10+c-'0',c=getchar(); return ret*f;}#define space() putchar(' ')#define nextline() putchar('\n')void pot(int x){if(!x)return;pot(x/10);putchar('0'+x%10);}void out(int x){if(!x)putchar('0');if(x<0)putchar('-'),x=-x;pot(x);}const int MAXN = 24;int n,m;int fac[MAXN],a[MAXN];int vis[MAXN],tim;void ct(int x){ x--; ++tim; for(int i=1;i<=n;i++){ int cur=x/fac[n-i],j; for(j=1;j<=n;j++){ if(vis[j]==tim)continue; if(cur==0) break; cur--; } vis[j]=tim; out(j);space(); x%=fac[n-i]; } nextline();}void rct(){ int ans=1; for(int i=1;i<=n;i++){ int tmp=0; for(int j=i+1;j<=n;j++){ if(a[j]