http://codeforces.com/contest/568/problem/B

题意就是给一个有n个元素的集合,现在需要求有多少个A的二元关系p,使得p是对称的,是传递的,但不是自反的。

首先只用(x1, x1), (x2, x2).....这种二元对形成的传递,对称,非自反的满足条件的方法数为2^n - 1(每一对可以选择出现或者不出现,全部出现的情况是自反的,所以减掉1)

其次,由于如果存在(a, b)a!=b的二元关系对,那么a,b这两个元素一定在某一个环中(根据对称一定有(b, a)又根据传递一定有(a, a)与(b, b)),那么答案就是求不是每个点都在某一个环中的方法数,那么这时把某一个环看成是一个集合。设G[i]表示i个点形成若干个集合的方法数,再令F[i][j]表示i个点形成j个集合的方法数,那么G[i] = sigma(F[i][j] | j <= i/2),下面计算F[i][j]:

      F[i][j] = F[i - 1][j] * j + F[i - 2][j - 1] * (i - 1)

就是指第i个元素可以放在之前的某一个集合中,也可以与之前的某一个元素形成个数为2的集合

在算出G[i]后,来统计答案,这时候需要枚举有多少个(x, x)这样的二元对,设为i个,那么剩下的点就有n-i个,剩下的点可以选择j个(2 <= j <= n - i)来形成若干个集合来与i个(x, x)的数对形成一个合法的答案。那么这里合法的大案数量就是

      sigma(C[n][i] * sigma(C[n - i][j] * G[j]))其中,1<=i<=n-2  2<=j<=n-i   C为组合数

#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define inf (-((LL)1<<40))
#define lson k<<1, L, mid
#define rson k<<1|1, mid+1, R
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a, b) memset(a, b, sizeof(a))
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define dec(i, a, b) for(int i = a; i >= b; i --) //typedef __int64 LL;
typedef long long LL;
const int MAXN = ;
const int MAXM = ;
const double eps = 1e-12;
const double PI = 4.0 * atan(1.0);
const int MOD = ; LL F[MAXN], C[MAXN][MAXN]; void initF(int n) {
F[] = C[][] = ;
rep (i, , n) {
F[i] = C[i][] = ;
rep (j, , i / ) {//C[i][j]表示i个点形成j个集合(环)的方案数
C[i][j] = ( C[i - ][j] * j % MOD + (i - ) * C[i - ][j - ] % MOD ) % MOD;
F[i] = ( F[i] + C[i][j] ) % MOD; //F[i]表示i个点形成若干个集合(环)的方案数
}
}
} void initC(int n) {
mem0(C);
C[][] = ;
rep (i, , n) {
C[i][] = C[i][i] = ;
rep (j, , n - ) //C[i][j]为组合数
C[i][j] = ( C[i - ][j - ] + C[i - ][j] ) % MOD;
}
} int main()
{
#ifndef ONLINE_JUDGE
FIN;
// FOUT;
#endif // ONLINE_JUDGE
initF();
initC();
int n;
while(cin >> n) {
LL ans = ;
//首先计算2^n - 1
rep (i, , n) ans = ans * % MOD;
ans = (ans - + MOD) % MOD; //sigma(C[n][i] * sigma(C[n - i][j] * G[j]))
rep (i, , n - ) {
int m = n - i;
LL S = ;
rep (j, , m) {
S = ( S + C[m][j] * F[j] ) % MOD;
}
ans = (ans + S * C[n][i]) % MOD;
}
cout << ans << endl;
}
return ;
}

codeforces315Div1 B Symmetric and Transitive的更多相关文章

  1. codeforces 569D D. Symmetric and Transitive(bell数+dp)

    题目链接: D. Symmetric and Transitive time limit per test 1.5 seconds memory limit per test 256 megabyte ...

  2. Codeforces 568B Symmetric and Transitive

    http://codeforces.com/contest/568/problem/B 题意:题意还挺绕的,其实就是说:要你求出一个图,要求保证其中有至少一个点不连任何边,然后其他连边的点构成的每个联 ...

  3. CodeForces 568B DP Symmetric and Transitive

    题意: 根据离散数学的内容知道,一个二元关系是一个二元有序组<x, y>的集合. 然后有一些特殊的二元关系,比如等价关系,满足三个条件: 自反性,任意的x,都有二元关系<x, x&g ...

  4. 数学用语中的 透明 transitive property

    1.透明 https://en.wikipedia.org/wiki/Equivalence_relation In mathematics, an equivalence relation is a ...

  5. How to implement equals() and hashCode() methods in Java[reproduced]

    Part I:equals() (javadoc) must define an equivalence relation (it must be reflexive, symmetric, and ...

  6. Discrete.Differential.Geometry-An.Applied.Introduction(sig2008)笔记

    -------------------------------------------------------------- Chapter 1: Introduction to Discrete D ...

  7. override equals in Java

    equals() (javadoc) must define an equality relation (it must be reflexive, symmetric, and transitive ...

  8. Java的Object对象

    Object对象是除了基础对象之外,所有的对象都需要继承的父对象,包括数组也继承了Object Object里面的关键函数罗列如下: clone();调用该函数需要实现 Cloneable,否则会抛出 ...

  9. Codeforces Round #315 (Div. 2) (ABCD题解)

    比赛链接:http://codeforces.com/contest/569 A. Music time limit per test:2 seconds memory limit per test: ...

随机推荐

  1. mysql 问题 Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdb

    异常错误:Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.c ...

  2. 微信公众号菜单添加小程序,miniprogram,pagepath参数详解,php开发公众号

    随着微信小程序功能的开发, 已经可以跟公众号打通了, 主要有两种方式: 1) 在公众号文章中插入小程序 2) 在公众号菜单中添加小程序 第一种方式, 子恒老师在前面的课程已经详细介绍过, 今天来讲第二 ...

  3. English trip V1 - 辅导课 VOCABULARY BRUSH UP(1-6) 词汇刷新 SA:Winona

    1.How Do you Feel Now?            形容词  adj.  = adjective                     Describe people and thi ...

  4. codeforces 578c//Weakness and Poorness// Codeforces Round #320 (Div. 1)

    题意:一个数组arr,一个数字x,要使arr-x的最大子段最小,问该最小值. 三分x,复杂度logn,内层是最大子段的模板,只能用n复杂度的.因为是绝对值最大,正负各求一次,取大的.精度卡得不得了,要 ...

  5. 开发环境运行正常,发布服务器后提示HTTP 错误 403.14 - Forbidden

    一.发布服务器后报错 今天在项目发布中遇到一件奇怪的事,开发完成的项目,发布到服务器上时 1. 发布到A服务器,一切正常 2. 发布到B服务器,提示403服务器错误 在同事电脑上重新打包发布代码,并发 ...

  6. mysql 随机获取数据并插入到数据库中

    insert into result (user_id, activity_id, number) select user_id, activity_id from `activity_record` ...

  7. dup的使用(二)

    转自:http://blog.csdn.net/yeyuangen/article/details/6852682 一个进程在此存在期间,会有一些文件被打开,从而会返回一些文件描述符,从shell中运 ...

  8. duilib CEditUI 禁止输入中文字符,禁止复制粘贴

    1.CEditUI 禁止使用中文输入法 在 CEditUI::DoEvent 函数中,添加代码: if(m_bOnlyEnglishChar && m_pWindow &&am ...

  9. SQL*Loader 详解

    在 Oracle 数据库中,我们通常在不同数据库的表间记录进行复制或迁移时会用以下几种方法: 1. A 表的记录导出为一条条分号隔开的 insert 语句,然后执行插入到 B 表中2. 建立数据库间的 ...

  10. Html.RenderPartial("")与Html.Partial("")区别

    这个HtmlHelper的扩展方法Partial,和HtmlHelper自带的 RenderPartial功能比较接近, 两者都可以输出一个Partial视图:其区别如下: <一>. Pa ...