D. Symmetric and transitive time limit/test 1.5 seconds memory limit per test 256 megabytes input standard input OUTPU T standard output
Little Johnny has recently learned about set theory. Now it 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 are an equivalence relation.
A setρof pairs (a, b) of elements of some set A is called a binary to 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 are reflexive (for all a It is true); It is symmetric (for all A, b it is true so if, then); It is transitive (if and, than).
Little Johnny is not completely a fool and him noticed that the ' the ' the ' the ' the ' the ' the ' Here's 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.
Here's your task:count the number of binary relations over a set of size n such that they are symmetric, transitive, but Not a equivalence relations (i.e. they are not reflexive).
Since their number may is very large (not 0, according to Little Johnny), print the remainder of an integer division of this Number by 109 + 7. Input
A single line contains a single integer n (1≤n≤4000). Output
In a I print the answer to the problem modulo 109 + 7. Sample Test (s) input
1
Output
1
Input
2
Output
3
Input
3
Output
10
Bell number
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
#define LL __int64
const int MOD = 1000000007;
LL t[4005],b[4005];
void Get_bell (int n,int mod) {
b[0]=1;
B[1]=1;
T[0]=1;
for (int i=2;i<=n;++i) {
t[i-1]=b[i-1];
for (int j=i-2;j>=0;--j)
t[j]= (t[j]+t[j+1])%mod;
B[I]=T[0];
}
int main () {
Get_bell (4001, MOD);
int n;
cin>>n;
LL A = b[n + 1];
LL B = b[n];
cout<< (a-b + MOD)% mod<<endl;
return 0;
}