题目链接:

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. Android在其他线程中更新UI

    public class TransferTools { private static final int MSG_START = 1001; private static final int MSG ...

  2. Android 中的Canvas画图

    Android中有一个Canvas类,Canvas类就是表示一块画布,你可以在上面画你想画的东西.当然,你还可以设置画布的属性,如画布的颜色/尺寸等.Canvas提供了如下一些方法: Canvas() ...

  3. pycharm pull到github

    1.setting中找到github 正确输入邮箱密码,勾上ssh 2.在本机中git bash 得到ssh代码 输入到github 个人setting中 3.在pycharm中setting项git ...

  4. Servlet 3.0的AsyncListener接口

    Servlet 3.0的AsyncListener接口 作者:chszs,转载需注明. 博客主页:http://blog.csdn.net/chszs 一.Servlet 3.0介绍 Servlet ...

  5. 【Unity3D自学记录】Unity3D之自制小钟表

    今天来写一个小钟表,事实上非常easy,就运用到了欧拉角. 首先创建时钟.分钟.秒钟以及4个点(12点.3点.6点.9点)偷懒了~~没弄那么多点. 时钟.分钟.秒钟这三个父级的中心一定要注意,我们旋转 ...

  6. C++11 并发指南一(C++11 多线程初探)(转)

    引言 C++11 自2011年发布以来已经快两年了,之前一直没怎么关注,直到最近几个月才看了一些 C++11 的新特性,今后几篇博客我都会写一些关于 C++11 的特性,算是记录一下自己学到的东西吧, ...

  7. Android摄像头採集的视频数据流怎样通过Socket实时发送到目标服务端

    分两块: 1.取得摄像头採集的视频流 2.发送到server端 protected MediaRecorder mMediaRecorder; private LocalServerSocket mL ...

  8. 排序&匿名函数

    nums=[11,34234,23,344,123,1,23,124,523,4,12342341,423,43545] nums.sort() print(nums) #这个就是排序,从小到到 匿名 ...

  9. Gson解析数组和list容器

    Gson解析数组和list容器 使用Gson解析首先须要增加架包文件:gson-2.2.4.jar 定义一个类Student: public class Student { String name=& ...

  10. 增加录像时间戳水印、 camera框架介绍

    http://blog.csdn.net/mirkerson/article/details/38920107 http://blog.csdn.net/jimbo_lee/article/detai ...