其他分享
首页 > 其他分享> > [状压DP思路妙题][AGC020F]Arcs on a Circle

[状压DP思路妙题][AGC020F]Arcs on a Circle

作者:互联网

Code

#include <bits/stdc++.h>

template <class T>
inline void read(T &res)
{
	res = 0; bool bo = 0; char c;
	while (((c = getchar()) < '0' || c > '9') && c != '-');
	if (c == '-') bo = 1; else res = c - 48;
	while ((c = getchar()) >= '0' && c <= '9')
		res = (res << 3) + (res << 1) + (c - 48);
	if (bo) res = ~res + 1;
}

template <class T>
inline T Min(const T &a, const T &b) {return a < b ? a : b;}

template <class T>
inline T Max(const T &a, const T &b) {return a > b ? a : b;}

typedef long double ld;

const int N = 8, M = 305, T = 34;

int n, C, l[N], p[N], f[M][M][T];
ld ans;

int main()
{
	read(n); read(C);
	for (int i = 1; i <= n; i++) read(l[i]), p[i] = i;
	std::sort(l + 1, l + n + 1);
	do
	{
		memset(f, 0, sizeof(f));
		f[0][l[n] * n][0] = 1;
		for (int i = 1; i < n * C; i++)
			for (int j = i; j <= n * C; j++)
				for (int S = 0; S < (1 << n - 1); S++)
				{
					f[i][j][S] += f[i - 1][j][S];
					int x = i % n; if (!x || ((S >> x - 1) & 1)) continue;
					f[i][Min(n * C, Max(j, i + l[p[x]] * n))]
						[S | (1 << x - 1)] += f[i - 1][j][S];
				}
		ans += f[n * C - 1][n * C][(1 << n - 1) - 1];
	} while (std::next_permutation(p + 1, p + n));
	for (int i = 1; i < n; i++) ans /= i * C;
	return printf("%.16Lf\n", ans), 0;
}

标签:const,条弧,Arcs,int,状压,妙题,起点,DP,小数
来源: https://www.cnblogs.com/xyz32768/p/12868629.html