CF569D Symmetric and Transitive(组合数+集合分划数)

Symmetric and Transitive

传送门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) 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, in this case we use a notation a ρba~^{\rho}b.

Binary relation is equivalence relation, if:

  • It is reflexive (for any a it is true that a ρaa~^{\rho}a);
  • It is symmetric (for any a,ba, b it is true that if a ρba~^{\rho}b, then b ρab~^{\rho}a);
  • It is transitive (if a ρb and b ρca~^{\rho}b \text{ and } b~^{\rho}c , than a ρca~^{\rho}c).

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 ρba~^{\rho}b, then b ρab~^{\rho}a (according to property (2)), which means a ρaa~^{\rho}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.

Input

A single line contains a single integer n(1n4000)n (1 \leq n \leq 4000).

Output

In a single line print the answer to the problem modulo 109 + 7.

Sample Input

3

Sample Output

10


题意

要求找出n个元素中满足对称性,传递性,但不满足自反性的所有二元关系种数。

分析

不难发现,所满足的情况为,A集合中随意挑k个元素,这些元素所自由组合后所形成的集合系的种数。
因为只要满足一个子集是A的真子集,那么,这个集合与自己的笛卡尔乘积一定满足题意。
所以我们每次只需要选择k个元素,对这k个元素进行划分即可。
Bell数(百度百科)

CODE

#include<cstdio>
#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;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章