问你n个元素中满足对称性和传递性但不满足自反性的二元关系集合的个数。
自反性:若a 则有(a, a)。
对称性:若(a, b) 则有 (b, a) 。
传递性:若(a, b) 且 (b, c) 则有 (a, c)。
样例3的10个集合为:
1.空集
2.{(a, a)}, 3.{(b, b)}, 4.{(c, c)}
5.{(a, a), (b, c)}, 6.{(a, a), (c, c)}, 7.{(b, b), (c, c)}
8.{(a, a), (b, b), (a, b), (b, a)}, 9.{(a, a), (c, c), (a, c), (c, a)}, 10.{(b, b), (c, c), (b, c), (c, b)}
参考了田神: 点击打开链接
AC代码:
#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
const int MAXN = 4005;
const int MOD = 1e9 + 7;
typedef long long ll;
ll dp[MAXN][MAXN];
int n;
int main(int argc, char const *argv[])
{
cin >> n;
dp[0][0] = 1;
for(int i = 1; i <= n; ++i) {
dp[i][0] = dp[i - 1][i - 1];
for(int j = 1; j <= i; ++j)
dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1]) % MOD;
}
cout << dp[n][n - 1] << endl;
return 0;
}