codeforces315Div1 B Symmetric and Transitive
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的更多相关文章
- 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 ...
- Codeforces 568B Symmetric and Transitive
http://codeforces.com/contest/568/problem/B 题意:题意还挺绕的,其实就是说:要你求出一个图,要求保证其中有至少一个点不连任何边,然后其他连边的点构成的每个联 ...
- CodeForces 568B DP Symmetric and Transitive
题意: 根据离散数学的内容知道,一个二元关系是一个二元有序组<x, y>的集合. 然后有一些特殊的二元关系,比如等价关系,满足三个条件: 自反性,任意的x,都有二元关系<x, x&g ...
- 数学用语中的 透明 transitive property
1.透明 https://en.wikipedia.org/wiki/Equivalence_relation In mathematics, an equivalence relation is a ...
- 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 ...
- Discrete.Differential.Geometry-An.Applied.Introduction(sig2008)笔记
-------------------------------------------------------------- Chapter 1: Introduction to Discrete D ...
- override equals in Java
equals() (javadoc) must define an equality relation (it must be reflexive, symmetric, and transitive ...
- Java的Object对象
Object对象是除了基础对象之外,所有的对象都需要继承的父对象,包括数组也继承了Object Object里面的关键函数罗列如下: clone();调用该函数需要实现 Cloneable,否则会抛出 ...
- Codeforces Round #315 (Div. 2) (ABCD题解)
比赛链接:http://codeforces.com/contest/569 A. Music time limit per test:2 seconds memory limit per test: ...
随机推荐
- 关于c#除法运算的问题
https://blog.csdn.net/yxt1522916229/article/details/51107569/ 下面的示例可以验证一下问题: 例如: int m = 2; ...
- 用Rails.5.2+ Vue.js做 vue-todolist app
Rails5.2+Vue.js完成Lists(curd) 注意: Edit/update使用SPA(single-page Application单页面程序)的方法完成.点击文字出现一个输入框和按钮. ...
- java通过java.net.URL发送http请求调用接口
一般在*.html,*.jsp页面中我们通过使用ajax调用接口,这个是我们通常用的.对于这些接口,大都是本公司写的接口供自己调用,所以直接用ajax就可以.但是,如果是多家公司共同开发一个东西,一个 ...
- laravel 异常深度解析
一.前言 做一件事,不仅要知其然,更要知其所以然.大部分的人都生活在别人设计的世界里,不是没有能力去更深一层,更进一步,而是因为自己懒得去思考.也许自己现在要做的就是:不要让自己舒服吧. 二.正题 1 ...
- python-day8-元组的内置方法
#为何要有元组,存放多个值,元组不可变,更多的是用来做查询# t=(1,[1,3],'sss',(1,2)) #t=tuple((1,[1,3],'sss',(1,2)))# print(type(t ...
- PHP header函数设置http报文头示例详解
//定义编码 header( 'Content-Type:text/html;charset=utf-8 '); //Atom header('Content-type: application/at ...
- VAE demo
先看tflearn 官方的: from __future__ import division, print_function, absolute_import import numpy as np i ...
- harbor私有镜像仓库的搭建与使用与主从复制
harbor私有镜像仓库,私有仓库有两种,一种是harbor,一种是小型的私有仓库,harbor有两种模式,一种是主 从,一种是高可用仓库,项目需求,需要两台服务器,都有docker.ldap权限统一 ...
- OPENWRT常用设置
常用设置: 计划任务,定时重启 系统--计划任务,每行一个计划任务. 然后是计划任务列表的格式: [minute] [hour] [day of month] [month] [day of week ...
- Solr安装入门
Solr安装入门:http://www.importnew.com/12607.html 查询详解:http://www.360doc.com/content/14/0306/18/203871_35 ...