/* -*- coding: utf-8 -*- * * 3262.cc: No.3262 豌エ濶イ繧ウ繝シ繝€繝シ縺輔s縲√◎縺ョ蝠城。慧蝠城。後〒縺吶h?(1<=d<=N) - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 8; /* typedef */ /* global variables */ int ls[MAX_N], rs[MAX_N]; int ps[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", ls + i, rs + i); for (int i = 0; i < n; i++) ps[i] = i; int cnt = 0; do { bool ok = true; for (int i = 0, px = 0; i < n; i++) { if (px > rs[ps[i]]) { ok = false; break; } px = max(px, ls[ps[i]]); } if (ok) cnt++; } while (next_permutation(ps, ps + n)); printf("%d\n", cnt); return 0; }