题目链接
- 题意:
求全排列的值大于给定值的概率(个数) - 分析:
简单DP,用来求全排列的某个性质
题目的一个限制为和,所以DP增加一维
const int MAXN = 12;
int ipt[MAXN][MAXN];
int dp[1 << 12][510];
int fac[20];
int main()
{
// freopen("in.txt", "r", stdin);
fac[0] = 1;
FE(i, 1, 19) fac[i] = fac[i - 1] * i;
int T, a, b;
RI(T);
REP(kase, T)
{
CLR(dp, 0);
RII(a, b);
REP(i, a) REP(j, a) RI(ipt[i][j]);
int all = (1 << a) - 1;
dp[0][0] = 1;
for (int i = 0; i <= all; i++)
{
int cnt = 0;
for (int j = 1; j <= all; j <<= 1) if(i & j) cnt++;
for (int j = 1, ct = 0; j <= all; j <<= 1, ct++)
{
if ((i & j) == 0)
{
for (int k = 0; k <= b; k++)
{
dp[i | j][min(b, k + ipt[cnt][ct])] += dp[i][k];
}
}
}
}
int x = fac[a], y = dp[all][b], t = __gcd(x, y);
x /= t; y /= t;
if (y)
printf("%d/%d\n", x, y);
else
puts("No solution");
}
return 0;
}