Codeforces Round #315 (Div. 2) D 贝尔数



链接:戳这里


D. Symmetric and Transitive
time limit per test1.5 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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 (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 ρ, 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 a, b it is true that if , then );
It is transitive (if  and , 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 n (1 ≤ n ≤ 4000).

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

Examples
input
1
output
1
input
2
output
3
input
3
output
10
Note
If n = 1 there is only one such relation — an empty one, i.e. . In other words, for a single element x of set A the following is hold: .

If n = 2 there are three such relations. Let's assume that set A consists of two elements, x and y. Then the valid relations are , ρ = {(x, x)}, ρ = {(y, y)}. It is easy to see that the three listed binary relations are symmetric and transitive relations, but they are not equivalence relations.


题意:

求1到n,n个元素组成的集合中,满足对称性和传递性但不满足自反性的二元组关系集合的个数

思路:

样例3:
空集
{<a, a>}, {<b, b>},{<c, c>}
{<a, a>, <b, b>},{<a, a>, <c, c>},{<b, b>, <c, c>}
{<a, a>, <b, b>, <a, b>, <b, a>},{<b, b>, <c, c>, <b, c>, <c, b>},{<a, a>, <c, c>, <a, c>, <c, a>} 一共10个


因为每组等价关系的个数正好等于Bell数,所以不难推出ans[i] = Bell[i + 1] - Bell[i],从下一个等价关系个数中减去从当前等价关系推出的个数即为当前不满足自反的二元组关系个数,直接推Bell三角形即可


代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
#define mod 1000000007
using namespace std;
ll dp[4010][4010];
int n;
int main(){
    dp[0][0]=1;
    for(int i=1;i<=4001;i++){
        dp[i][0]=dp[i-1][i-1];
        for(int j=1;j<=i;j++){
            dp[i][j]=(dp[i][j-1]+dp[i-1][j-1])%mod;
        }
    }
    scanf("%d",&n);
    printf("%I64d\n",dp[n][n-1]);
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值