题目链接:

D. Symmetric and Transitive

time limit per test

1.5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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:

  1. It is reflexive (for any a it is true that );
  2. It is symmetric (for any ab it is true that if , then );
  3. 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 by10^9 + 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 10^9 + 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.

题意:

问有n个元素,一共可以组成多少个有对称性和传递性但没有自反性的集合;

思路:

bell数,用递推公式加dp解决;

AC代码:

/*2014300227    569D - 21    GNU C++11    Accepted    62 ms    62692 KB*/
#include <bits/stdc++.h>
using namespace std;
const int N=12e5+; typedef long long ll;
const ll mod=1e9+;
const double PI=acos(-1.0);
int dp[][];
int main()
{
int n;
scanf("%d",&n); dp[][]=;
for(int i=;i<=n;i++)
{ dp[i][]=dp[i-][i-];
for(int j=;j<=n;j++)
{
dp[i][j]=(dp[i][j-]+dp[i-][j-])%mod;
}
}
ll ans=;
for(int i=;i<=n;i++)
{
ans+=dp[n][i];
ans%=mod;
}
cout<<ans<<"\n"; return ;
}

最新文章

  1. java基础(三)
  2. 转载:[AngularJS系列] 那伤不起的provider们啊~ (Provider, Value, Constant, Service, Factory, Decorator)
  3. LeetCode 01 Two Sum swift
  4. mycat 9066管理端口 常用命令
  5. URAL 2019 Pair: normal and paranormal (贪心) -GDUT联合第七场
  6. IEA For PCS7
  7. JAVA定义接口格式:
  8. eclipse中安装svn插件
  9. 【转】IOS开发:[1]Xcode5界面入门
  10. .net如何调试dll
  11. (六)学习MVC之标签a提交页面
  12. [jquery] jQuery点滴[持续更新]
  13. HDOJ 1202 The calculation of GPA
  14. HTML+CSS笔记 CSS入门续集
  15. Android Stduio的使用(七)--Structure窗口
  16. [转]在node.js中,使用基于ORM架构的Sequelize,操作mysql数据库之增删改查
  17. dockerfile语法规则
  18. pythonのpygame初体验
  19. 《mysql必知必会》学习_第20章_20180809_欢
  20. CentOS7 彻底关闭 IPV6

热门文章

  1. ubuntu允许mysql远程连接
  2. fastscript增加公共函数
  3. win7 32位配置apache+wsgi+django环境
  4. npm升级所有可更新包
  5. Codeforces Round #313 (Div. 2) ABC
  6. jstl的函数
  7. c语言-递推算法1
  8. Linux基础(3)- 正文处理命令及tar命令、vi编辑器、硬盘分区、格式化及文件系统的管理和软连接、硬连接
  9. Android 5.0状态栏和导航栏
  10. 惊艳的cygwin——Windows下的Linux命令行环境的配置和使用