传送门1
传送门2
Little Johnny has recently learned about set theory. Now he is studying binary relations. You’ve probably heard the term “equivalence relation”. These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation.
A set ρ \rho ρ of pairs ( a , b ) (a, b) (a, b) of elements of some set A is called a binary relation on set A. For two elements a and b of the set A we say that they are in relation ρ \rho ρ, if pair ( a , b ) ∈ ρ (a,b)\in \rho (a,b)∈ρ, in this case we use a notation a ρ b a~^{\rho}b a ρb.
Binary relation is equivalence relation, if:
Little Johnny is not completely a fool and he noticed that the first condition is not necessary! Here is his “proof”:
Take any two elements, a and b. If a ρ b a~^{\rho}b a ρb, then b ρ a b~^{\rho}a b ρa (according to property (2)), which means a ρ a a~^{\rho}a a ρa (according to property (3)).
It’s very simple, isn’t it? However, you noticed that Johnny’s “proof” is wrong, and decided to show him a lot of examples that prove him wrong.
Here’s your task: count the number of binary relations over a set of size n such that they are symmetric, transitive, but not an equivalence relations (i.e. they are not reflexive).
Since their number may be very large (not 0, according to Little Johnny), print the remainder of integer division of this number by 109 + 7.
A single line contains a single integer n ( 1 ≤ n ≤ 4000 ) n (1 \leq n \leq 4000) n(1 ≤ n ≤ 4000).
In a single line print the answer to the problem modulo 109 + 7.
3
10
要求找出n个元素中满足对称性,传递性,但不满足自反性的所有二元关系种数。
不难发现,所满足的情况为,A集合中随意挑k个元素,这些元素所自由组合后所形成的集合系的种数。
因为只要满足一个子集是A的真子集,那么,这个集合与自己的笛卡尔乘积一定满足题意。
所以我们每次只需要选择k个元素,对这k个元素进行划分即可。
Bell数(百度百科)
#include
#define FOR(i,a,b) for(int i=(a),i##_END_=(b);i<=i##_END_;i++)
#define N 4005
#define P 1000000007
typedef long long LL;
LL Bell[N][N],C[N][N];
//集合分划数,组合数
int main() {
int n;
scanf("%d",&n);
Bell[0][0]=Bell[1][1]=C[1][0]=C[1][1]=1;
FOR(i,2,n) {
C[i][0]=C[i][i]=1;
C[i][1]=i;
Bell[i][1]=Bell[i-1][i-1];
FOR(j,2,i) {
Bell[i][j]=(Bell[i][j-1]+Bell[i-1][j-1])%P;
C[i][j]=(C[i-1][j-1]+C[i-1][j])%P;
}
}
LL ans=1;
FOR(i,1,n-1)ans=(ans+C[n][i]*Bell[i][i])%P;
//为不满足自反性,i不为n
printf("%lld\n",ans);
return 0;
}