codeforces 569D D. Symmetric and Transitive(bell数+dp)
题目链接:
1.5 seconds
256 megabytes
standard input
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:
- 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 by10^9 + 7.
A single line contains a single integer n (1 ≤ n ≤ 4000).
In a single line print the answer to the problem modulo 10^9 + 7.
1
1
2
3
3
10
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)的更多相关文章
- Bell(hdu4767+矩阵+中国剩余定理+bell数+Stirling数+欧几里德)
Bell Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- Stirling数,Bell数,Catalan数,Bernoulli数
组合数学的实质还是DP,但是从通式角度处理的话有利于FFT等的实现. 首先推荐$Candy?$的球划分问题集合: http://www.cnblogs.com/candy99/p/6400735.ht ...
- Bell数和Stirling数
前面说到了Catalan数,现在来了一个Bell数和Stirling数.什么是Bell数,什么是Stirling数呢?两者的关系如何,有用于解决什么算法问题呢? Bell数是以Bell这个人命名的,组 ...
- 恶补---bell数
定义 bell数即一个集合划分的数目 示例 前几项的bell数列为 1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975 ,... 求值方法 1.bell ...
- Bell数入门
贝尔数 贝尔数是以埃里克·坦普尔·贝尔命名,是组合数学中的一组整数数列,开首是(OEIS的A000110数列): $$B_0 = 1, B_1 = 1, B_2 = 2, B_3 = 5, B_4 = ...
- (转) [组合数学] 第一类,第二类Stirling数,Bell数
一.第二类Stirling数 定理:第二类Stirling数S(p,k)计数的是把p元素集合划分到k个不可区分的盒子里且没有空盒子的划分个数. 证明:元素在哪些盒子并不重要,唯一重要的是各个盒子里装的 ...
- Codeforces Round #620 F2. Animal Observation (hard version) (dp + 线段树)
Codeforces Round #620 F2. Animal Observation (hard version) (dp + 线段树) 题目链接 题意 给定一个nm的矩阵,每行取2k的矩阵,求总 ...
- Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)
题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...
- 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 ...
随机推荐
- 关于Label::createWithBMFont中资源文件使用的坑爹问题解决方式
1.问题 使用Label的createWithBMFont,结果.fnt的资源总是找不到或者获取数据失败.原来.fnt资源的使用须要配合该资源的.png共同 使用,如bitmapFontTest3.f ...
- 综合运用: C++11 多线程下生产者消费者模型详解(转)
生产者消费者问题是多线程并发中一个非常经典的问题,相信学过操作系统课程的同学都清楚这个问题的根源.本文将就四种情况分析并介绍生产者和消费者问题,它们分别是:单生产者-单消费者模型,单生产者-多消费者模 ...
- 命令行查看w3wp进程信息
用windbg.mdbg等调试器调试时,当出现多个w3wp进程并且用户名相同,需要区分每个w3wp进程对应的PID(进程ID)和应用程序池信息. 我们用以下方式得到每个w3wp进程的详细信息. Win ...
- 【凯子哥带你夯实应用层】使用ActionProvider实现子菜单时遇到的一个坑
转载请注明出处:http://blog.csdn.net/zhaokaiqiang1992 近期在重温Android基础.在看到ActionProvider的时候遇到一个坑.分享到大家,避免入坑. 首 ...
- Python+Selenium框架 ---自动化测试报告的生成
本文来介绍如何生成自动化测试报告,前面文章尾部提到了利用HTMLTestRunner.py来生成自动化测试报告.关于HTMLTestRunner不过多介绍,只需要知道是一个能生成一个HTML格式的网页 ...
- viewpager 跳转到指定页面
viewPager.setCurrentItem(getUserIndex(userId)); seCurrentItem是定位到指定页面参数是position
- vs学习过程中遇见的各种问题
1. argument to type "char *"is incompatible with parameter of type "LPWSTR" 解决: ...
- c# 委托 Predicate的使用示例
一.说明 委托Predicate 可以有参数(比如下面的示例),也可以不带参数,委托Predicate是返回固定值bool值的委托 二.示例代码(控制台程序) using System; using ...
- types of transfrmations
http://math.wallawalla.edu/~duncjo/courses/math113/winter08/notes/9-1_math113.pdf Name What Changes ...
- Jsp中操作页面显示
通常我们想改变网页中的显示可以用下面的方式. <script type="text/javascript">function show(){ document. ...