# [FJOI2016] 建筑师

2
3 2 2
3 1 2

2
1

## 题解

${f}_{i,j,k}$$f_{i,j,k}$ 为 前 $i$$i$ 个中， 从左边能看到 $j$$j$ 个， 从右边能看到 $k$$k$ 个的方案数。
${f}_{i,j,k}={f}_{i-1,j-1,k}+{f}_{i-1,j,k-1}+{f}_{i-1,j,k}×\left(i-2\right)$$f_{i,j,k} =f_{i−1,j−1,k} + f_{i−1, j, k−1} + f_{i−1, j, k} \times (i − 2)$

${f}_{i,j}={f}_{i-1,j-1}+{f}_{i-1,j}×\left(i-1\right)$$f_{i, j} = f_{i - 1, j - 1} + f_{i - 1, j} \times (i - 1)$

## 代码

#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <queue>
#include <set>
#include <stack>

#define R register
#define ll long long
#define db double
#define sqr(_x) (_x) * (_x)
#define Cmax(_a, _b) ((_a) < (_b) ? (_a) = (_b), 1 : 0)
#define Cmin(_a, _b) ((_a) > (_b) ? (_a) = (_b), 1 : 0)
#define Max(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define Min(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define Abs(_x) (_x < 0 ? (-(_x)) : (_x))

using namespace std;

namespace Dntcry
{
{
R int a = 0, b = 1; R char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) (c == '-') ? b = -1 : 0;
for(; c >= '0' && c <= '9'; c = getchar()) a = (a << 1) + (a << 3) + c - '0';
return a * b;
}
{
R ll a = 0, b = 1; R char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) (c == '-') ? b = -1 : 0;
for(; c >= '0' && c <= '9'; c = getchar()) a = (a << 1) + (a << 3) + c - '0';
return a * b;
}
const int Maxn = 50010, Maxl = 210, Mod = 1000000007;
int T, n, A, B;
ll S[Maxn][Maxl], C[Maxl][Maxl];
void init(R int tmp1, R int tmp2)
{
for(R int i = 0; i <= tmp1; i++)
{
S[i][0] = 0;
if(i <= tmp2) S[i][i] = 1;
for(R int j = 1; j <= Min(i, tmp2); j++)
S[i][j] = (S[i - 1][j - 1] + (i - 1) * S[i - 1][j] % Mod) % Mod;
}
for(R int i = 0; i <= tmp2; i++)
{
C[i][0] = 1;
for(R int j = 1; j <= i; j++)
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % Mod;
}
return ;
}
int Main()
{
init(50000, 200);
while(T--)
{
printf("%lld\n", S[n - 1][A + B - 2] * C[A + B - 2][A - 1] % Mod);
}
return 0;
}
}
int main()
{
return Dntcry :: Main();
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120