题目地址:New Language
题意:求1到n,n个元素组成的集合中,满足对称性和传递性但不满足自反性的二元组关系集合的个数。
思路:对于每组的对应关系中,正好满足贝尔数(其实是贝尔三角形每行的和)
由图中红框中可以发现上一行的总和=下一行的n-1位置上的数。然后其实上贝尔数的板子就好了。
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-6;
const int maxn=4010;
const int mod=1e9+7;
LL dp[maxn][maxn];
int main()
{
dp[0][0]=1;
for(int i=1;i<maxn;i++){
dp[i][0]=dp[i-1][i-1]%mod;
for(int j=1;j<maxn;j++){
dp[i][j]=((dp[i][j-1]+dp[i-1][j-1])%mod+mod)%mod;
}
}
int n;
while(~scanf("%d",&n)){
printf("%lld\n",dp[n][n-1]);
}
return 0;
}