记录编号 101716 评测结果 AAAAAAAAAA
题目名称 棋盘放車 最终得分 100
用户昵称 GravatarOI永别 是否通过 通过
代码语言 C 运行时间 0.156 s
提交时间 2014-05-13 21:49:36 内存使用 8.29 MiB
显示代码纯文本
#include<stdio.h>
#define N 25
#define LL long long
int a[N];
LL f[(1 << 20) + 5];
int n, m;
inline int lowbit(int x){
	return x & (- x);
}
int i;
int main(){
	FILE *fin, *fout;
	fin = fopen("examone.in","r");
	fout = fopen("examone.out", "w");
	fscanf(fin,"%d %d", &n, &m);
	int ms = (1 << n) - 1;
	int x, y;
	for (i = 1; i <= m; i ++){
		fscanf(fin, "%d %d", &x, &y);
		a[x] |= (1 << (y - 1));
	}
	f[0] = 1;
	//for (int i = 1; i <= ms; i ++) f[i] = 1;
	for (i = 1; i <= ms; i ++){
		int temp, num = 0;
		for (temp = i; temp ; temp -= lowbit(temp))
			num ++;
		temp = i & (~ a[num]);
		while (temp){
			f[i] += f[i ^ lowbit(temp)];
			temp -= lowbit(temp);
		}
	}
	fprintf(fout,"%lld\n", f[ms]);
	fclose(fin);
	fclose(fout);
	return 0;
}