爱奇艺第一题暴力36...太难啦太难啦
#include<iostream> #include<vector> using namespace std; long long res = 0; void dfs(int n, bool * a, int pos, int deep, vector<bool> visit) { if (deep == n) { res = (res + 1) % (1000000007); return; } visit[pos] = 1; for (int i = 0; i < n; i++) { if (visit[i] == 1) continue; if ((a[deep-1] == 1 && i < pos) || (a[deep-1] == 0 && i > pos)) { dfs(n, a, i, deep + 1, visit); } } visit[pos] = 0; } int main() { int n; cin >> n; bool * a = new bool[n - 1]; for (int i = 0; i < n - 1; i++) cin >> a[i]; vector<bool> visit(n, 0); res = 0; for (int i = 0; i < n; i++) dfs(n, a, i, 1, visit); cout << res << endl; return 0; }
#爱奇艺##题解#