题目链接:

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

codeforces 569D D. Symmetric and Transitive(bell数+dp)的更多相关文章

  1. Bell(hdu4767+矩阵+中国剩余定理+bell数+Stirling数+欧几里德)

    Bell Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status  ...

  2. Stirling数,Bell数,Catalan数,Bernoulli数

    组合数学的实质还是DP,但是从通式角度处理的话有利于FFT等的实现. 首先推荐$Candy?$的球划分问题集合: http://www.cnblogs.com/candy99/p/6400735.ht ...

  3. Bell数和Stirling数

    前面说到了Catalan数,现在来了一个Bell数和Stirling数.什么是Bell数,什么是Stirling数呢?两者的关系如何,有用于解决什么算法问题呢? Bell数是以Bell这个人命名的,组 ...

  4. 恶补---bell数

    定义 bell数即一个集合划分的数目 示例 前几项的bell数列为 1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975 ,... 求值方法 1.bell ...

  5. Bell数入门

    贝尔数 贝尔数是以埃里克·坦普尔·贝尔命名,是组合数学中的一组整数数列,开首是(OEIS的A000110数列): $$B_0 = 1, B_1 = 1, B_2 = 2, B_3 = 5, B_4 = ...

  6. (转) [组合数学] 第一类,第二类Stirling数,Bell数

    一.第二类Stirling数 定理:第二类Stirling数S(p,k)计数的是把p元素集合划分到k个不可区分的盒子里且没有空盒子的划分个数. 证明:元素在哪些盒子并不重要,唯一重要的是各个盒子里装的 ...

  7. Codeforces Round #620 F2. Animal Observation (hard version) (dp + 线段树)

    Codeforces Round #620 F2. Animal Observation (hard version) (dp + 线段树) 题目链接 题意 给定一个nm的矩阵,每行取2k的矩阵,求总 ...

  8. Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)

    题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...

  9. Codeforces Round #272 (Div. 1)D(字符串DP)

    D. Dreamoon and Binary time limit per test 2 seconds memory limit per test 512 megabytes input stand ...

随机推荐

  1. 关于Label::createWithBMFont中资源文件使用的坑爹问题解决方式

    1.问题 使用Label的createWithBMFont,结果.fnt的资源总是找不到或者获取数据失败.原来.fnt资源的使用须要配合该资源的.png共同 使用,如bitmapFontTest3.f ...

  2. 综合运用: C++11 多线程下生产者消费者模型详解(转)

    生产者消费者问题是多线程并发中一个非常经典的问题,相信学过操作系统课程的同学都清楚这个问题的根源.本文将就四种情况分析并介绍生产者和消费者问题,它们分别是:单生产者-单消费者模型,单生产者-多消费者模 ...

  3. 命令行查看w3wp进程信息

    用windbg.mdbg等调试器调试时,当出现多个w3wp进程并且用户名相同,需要区分每个w3wp进程对应的PID(进程ID)和应用程序池信息. 我们用以下方式得到每个w3wp进程的详细信息. Win ...

  4. 【凯子哥带你夯实应用层】使用ActionProvider实现子菜单时遇到的一个坑

    转载请注明出处:http://blog.csdn.net/zhaokaiqiang1992 近期在重温Android基础.在看到ActionProvider的时候遇到一个坑.分享到大家,避免入坑. 首 ...

  5. Python+Selenium框架 ---自动化测试报告的生成

    本文来介绍如何生成自动化测试报告,前面文章尾部提到了利用HTMLTestRunner.py来生成自动化测试报告.关于HTMLTestRunner不过多介绍,只需要知道是一个能生成一个HTML格式的网页 ...

  6. viewpager 跳转到指定页面

    viewPager.setCurrentItem(getUserIndex(userId)); seCurrentItem是定位到指定页面参数是position

  7. vs学习过程中遇见的各种问题

    1.  argument to type "char *"is incompatible with parameter of type "LPWSTR" 解决: ...

  8. c# 委托 Predicate的使用示例

    一.说明 委托Predicate 可以有参数(比如下面的示例),也可以不带参数,委托Predicate是返回固定值bool值的委托 二.示例代码(控制台程序) using System; using ...

  9. types of transfrmations

    http://math.wallawalla.edu/~duncjo/courses/math113/winter08/notes/9-1_math113.pdf Name What Changes ...

  10. Jsp中操作页面显示

    通常我们想改变网页中的显示可以用下面的方式. <script type="text/javascript">function show(){     document. ...