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. WPF样式——经典博客

    WPF样式博客:http://www.cnblogs.com/luluping/archive/2011/05/06/2039498.html

  2. robot framework学习笔记2

    声明:本笔记都只是自己根据大牛虫师的robot系列文档学习记录的,学习的话还请移步虫师博客:https://www.cnblogs.com/fnng/ 非常感谢大牛的分享,带小白一步一步入门   F5 ...

  3. matplotlib.pyplot 绘制图形

    收集的一些觉得非常有用的绘图的资料: Python--matplotlib绘图可视化知识点整理 matplotlib.pyplot matplotlib gallery

  4. js 刷新页面

    Javascript刷新页面的几种方法:1 history.go(0)2 window.location.reload() window.location.reload(true) 3 locatio ...

  5. maven 3.5.2 修改java_home

        修改mvn.cmd文件,找到: @REM ==== START VALIDATION ==== if not "%JAVA_HOME%" == "" g ...

  6. POJ 2352 treap

    当年经常遇到这种题,愣是没做出来,好像那时不会线段树,也不会平衡树. 凭借一身蛮力来搞,倒是和那群朋友搞得开开心心. 题意: y从小到大,若y相同,x从小到大,这样给出一些坐标,求每个点覆盖的点个数. ...

  7. Asterisk——part 1

    Asterisk Russell Bryant Asterisk1 is an open source telephony applications platform distributed unde ...

  8. 深入理解MyBatis中的一级缓存与二级缓存

    http://blog.csdn.net/weixin_36380516/article/details/73194758   先说缓存,合理使用缓存是优化中最常见的,将从数据库中查询出来的数据放入缓 ...

  9. Rotate Array 旋转数组 JS 版本解法

    Given an array, rotate the array to the right by k steps, where k is non-negative. 给定一个数组,并且给定一个非负数的 ...

  10. 微信小程序跨页面获取数据示例

    index.wxml <navigator class="navs" url="{{urls}}"> 中国 </navigator> i ...