比赛 |
20160323 |
评测结果 |
AAAAAAAAAA |
题目名称 |
雕塑安置 |
最终得分 |
100 |
用户昵称 |
Fmuckss |
运行时间 |
0.497 s |
代码语言 |
C++ |
内存使用 |
168.31 MiB |
提交时间 |
2016-03-24 08:24:53 |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long f[21][1<<20];
int cant[21];
int settle[21];
int top;
int n, m;
long long ans;
void make_settle() {
for(int i = 1; i <= n; i++) {
settle[i] = 1<<(i-1);
top += settle[i];
}
}
void read() {
scanf("%d %d", &n, &m);
int x, y;
for(int i = 1; i <= m; i++) {
scanf("%d %d", &x, &y);
cant[x] += 1<<(y-1);
}
}
bool judge(int num, int tar, int line) {
if(num & settle[tar]) return false;
if(cant[line] & settle[tar]) return false;
return true;
}
void solve() {
f[0][0] = 1;
for(int i = 1; i <= n; i++) {
for(int j = 0; j <= top; j++) {
if(!f[i-1][j]) continue;
for(int k = 1; k <= n; k++) {
if(!judge(j, k, i)) continue;
f[i][j | settle[k]] += f[i-1][j];
}
}
}
for(int i = 0; i <= top; i++) {
ans += f[n][i];
}
printf("%lld", ans);
}
void dfs(int line, int now) {
if(line == n+1) { ans++; return; }
for(int i = 1; i <= n; i++) {
if((cant[line] & settle[i])||(settle[i] & now)) continue;
dfs(line+1, settle[i] | now);
}
}
int main() {
freopen("arrange.in", "r", stdin);
freopen("arrange.out", "w", stdout);
read();
make_settle();
if(n <= 8) {
dfs(1, 0);
printf("%lld\n", ans);
return 0;
}
solve();
return 0;
}