文章目錄
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 of pairs 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 , if pair , in this case we use a notation .
Binary relation is equivalence relation, if:
- It is reflexive (for any a it is true that );
- It is symmetric (for any it is true that if , then );
- It is transitive (if , than ).
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 , then (according to property (2)), which means (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 .
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;
}