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) (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:

  • It is reflexive (for any a it is true that a   ρ a a~^{\rho}a a ρa);
  • It is symmetric (for any a , b a, b a,b it is true that if a   ρ b a~^{\rho}b a ρb, then b   ρ a b~^{\rho}a b ρa);
  • It is transitive (if a   ρ b  and  b   ρ c a~^{\rho}b \text{ and } b~^{\rho}c a ρb and b ρc , than a   ρ c a~^{\rho}c a ρ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   ρ 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.

Input

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

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;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值