比赛 20160323 评测结果 ATAAAAATTT
题目名称 雕塑安置 最终得分 60
用户昵称 lxtgogogo 运行时间 4.570 s
代码语言 C++ 内存使用 16.31 MiB
提交时间 2016-03-23 20:43:02
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<iomanip>
#include<ctime>
#include<queue>
#include<cmath>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch>'9' || ch<'0')	{if(ch=='-'){f=-1;}ch=getchar();}
	while(ch>='0' && ch<='9')	{x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}
const int r=1<<20;
int n=0,m=0,final=0;
int can[22]={};//1表示能放
long long dp[2][r]={};
long long ans=0;

void init(){
	n=read();m=read();
	final=(1<<n)-1;
	for(int i=1;i<=n;i++)	can[i]=final;;
	for(int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		can[x]=can[x]^(1<<(y-1));
	}
}
void work(int k,int s){
	if(k>n)	ans++;
	if((s&can[k])!=0)
	{
		int y=(s&can[k]);
		int x=y&(-y);
		while(x>0)
		{
			work(k+1,s-x);
			y-=x;
			x=y&(-y);
		}
	}
}
int main(){
	freopen("arrange.in","r",stdin);
	freopen("arrange.out","w",stdout);
	
	init();
	work(1,final);
	cout<<ans<<endl;
	
	fclose(stdin);fclose(stdout);
	return 0;
}