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 ...
随机推荐
- 使用viewPage实现图片轮播
概述 图片循环播放这种效果,在许多的场合都能看到,只要一打开各大主流网站的首页几乎都有一个这样的组件,它可以很显目的提供给用户最近最火热的信息.因为它应用得如此之广泛,今天,我们就来写一下这个组件. ...
- 【JVM】idea启动项目时候 添加jvm启动参数显示详细日志
-verbose:class
- 三维场景如何嵌入到PPT中展示?
今天要跟大家一起交流的大体内容如标题所示,日常生活中,ppt已经成为人们工作学习生活中不可或缺的工具之一,那么三维场景是如何在ppt中加载展示的呢?请大家慢慢往下看. 1.创建命令按钮和web bro ...
- vscode格式化代码无效--可能的解决方法
因为vscode默认启用了根据文件类型自动设置tabsize的选项,因此,可以通过关闭自动设置选项,防止格式覆盖.在用户设置里添加如下配置即可: "editor.detectIndentat ...
- Windows 无法卸载IE9怎么办
1 如下图所示,使用自带的卸载工具无法卸载IE9 运行命令提示符,粘贴下面的命令 FORFILES /P %WINDIR%\servicing\Packages /M Microsoft-Window ...
- 广告制胜无它,顺应人性尔——leo鉴书63
近期看了几本怎样写文案的书.对广告有了些兴趣.查了下相关销量排行,位置比較高的是本叫<科学的广告+我的广告生涯>的书,是同一作者(Claude C. Hopkins)两本书的合集.前者是他 ...
- Android最佳实践之Material Design
Material概述及主题 学习地址:http://developer.android.com/training/material/get-started.html 使用material design ...
- C#对象实例化
C#常用的对象实例化有以下几种方式: using System; using System.Collections.Generic; using System.Linq; using System.R ...
- mysql报错锦集
MySQL 启动报错 - ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/ ...
- linux实现php定时执行cron任务详解(转)
对于PHP本身并没有一套解决方案来执行定时任务,不过是借助sleep函数完成的.这种方就是要提前做一些配置,如实现过程: 复制代码 代码如下: ignore_user_abort();//关掉浏览器, ...