# CF11 D. A Simple Task

$n$​很小的话，考虑状压

$F[S][i]$表示点集$S$中遍历到$i$的方案数

/*program from Wolfycz*/
#include<map>
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define Fi first
#define Se second
#define ll_inf 1e18
#define MK make_pair
#define sqr(x) ((x)*(x))
#define pii pair<int,int>
#define int_inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
static char buf[1000000],*p1=buf,*p2=buf;
}
template<typename T>inline T frd(T x){
int f=1; char ch=gc();
for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')    f=-1;
for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
int f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
inline void print(int x){
if (x<0)	putchar('-'),x=-x;
if (x>9)	print(x/10);
putchar(x%10+'0');
}
const int N=20;
bool Map[N+10][N+10];
ll F[(1<<N)+10][N+10];
int lowbit(int x){for (int i=0;;i++)	if ((1<<i)&x)	return i;}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
ll Ans=0;
for (int i=1;i<=m;i++){
Map[x][y]=Map[y][x]=1;
}
for (int i=0;i<n;i++)	F[1<<i][i]=1;
for (int sta=1;sta<1<<n;sta++){
for (int i=0;i<n;i++){
if (!F[sta][i])	continue;
int p=lowbit(sta);
for (int j=p;j<n;j++){
if (!Map[i][j])	continue;
if (sta&(1<<j)){
if (j==p)
Ans+=F[sta][i];
}else	F[sta|(1<<j)][j]+=F[sta][i];
}
}
}
printf("%lld\n",(Ans-m)>>1);
return 0;
}


CF

posted @ 2021-08-06 15:29  Wolfycz  阅读(12)  评论(0编辑  收藏  举报