Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define x first
- #define y second
- using namespace std;
- typedef long long ll;
- const int MAXN = 100500;
- const int N = 25;
- ll dp[N][N];
- ll n, a, b;
- int p[N];
- ll C[N][N];
- ll fact[N];
- bool used[N];
- double ans[N];
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin >> n >> a >> b;
- for (int i = 0; i < n; i++)
- {
- cin >> p[i];
- p[i]--;
- }
- fact[0] = 1;
- C[0][0] = 1;
- for (int i = 0; i < N - 1; i++)
- {
- fact[i + 1] = (ll)(i + 1) * fact[i];
- for (int j = 0; j < N - 1; j++)
- {
- C[i + 1][j + 1] += C[i][j];
- C[i + 1][j] += C[i][j];
- }
- }
- for (int i = 1; i <= n; i++)
- {
- dp[i][1] = fact[i - 1];
- }
- for (int sz = 2; sz <= n; sz++)
- {
- for (int i = 1; i <= n; i++)
- {
- for (int k = 1; k <= i; k++)
- {
- dp[i][sz] += dp[i - k][sz - 1] * fact[k - 1] * C[i - 1][k - 1];
- }
- }
- }
- int cur_cycles = 0;
- for (int i = 0; i < n; i++)
- {
- if (!used[i])
- {
- cur_cycles++;
- int j = i;
- while (!used[j])
- {
- used[j] = true;
- j = p[j];
- }
- }
- }
- double best_ans;
- bool is_ba_found = false;
- for (int strat = 1; strat <= n; strat++)
- {
- double lower_res = 0;
- double q = 0;
- for (int c = n; c >= 1; c--)
- {
- if (c >= strat)
- {
- ans[c] = (double)(n - c) * a;
- lower_res += ans[c] * dp[n][c];
- }
- else
- {
- ans[c] = b / q +
- }
- }
- if (best_ans)
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement