\(\color{#0066ff}{ 题目描述 }\)

刚刚解决完电力网络的问题, 阿狸又被领导的任务给难住了. 刚才说过, 阿狸的国家有n个城市, 现在国家需要在某些城市对之间建立一些贸易路线, 使得整个国家的任意两个城市都直接或间接的连通. 为了省钱, 每两个城市之间最多只能有一条直接的贸易路径. 对于两个建立路线的方案, 如果存在一个城市对, 在两个方案中是否建立路线不一样, 那么这两个方案就是不同的, 否则就是相同的. 现在你需要求出一共有多少不同的方案. 好了, 这就是困扰阿狸的问题. 换句话说, 你需要求出n个点的简单(无重边无自环)无向连通图数目. 由于这个数字可能非常大, 你只需要输出方案数mod 1004535809(479 * 2 ^ 21 + 1)即可.

\(\color{#0066ff}{输入格式}\)

一行,四个整数,N、M、x、|S|,其中|S|为集合S中元素个数。第二行,|S|个整数,表示集合S中的所有元素。

\(\color{#0066ff}{输出格式}\)

一行,一个整数,表示你求出的种类数mod 1004535809的值。

\(\color{#0066ff}{输入样例}\)

3

4

100000

\(\color{#0066ff}{输出样例}\)

4

38

829847355

\(\color{#0066ff}{数据范围与提示}\)

对于 20%的数据, n <= 10

对于 40%的数据, n <= 1000

对于 60%的数据, n <= 30000

对于 80%的数据, n <= 60000

对于 100%的数据, n <= 130000

\(\color{#0066ff}{ 题解 }\)

直接构造出g,求个ln(指数生成函数)

最初系数/i!是好算,最后要乘回来

#include<bits/stdc++.h>
#define LL long long
LL in() {
char ch; LL x = 0, f = 1;
while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
return x * f;
}
using std::vector;
const int maxn = 1e6 + 20;
const int mod = 1004535809;
int len, r[maxn];
LL ksm(LL x, LL y) {
LL re = 1LL;
while(y) {
if(y & 1) re = re * x % mod;
x = x * x % mod;
y >>= 1;
}
return re;
}
void FNTT(vector<int> &A, int flag) {
A.resize(len);
for(int i = 0; i < len; i++) if(i < r[i]) std::swap(A[i], A[r[i]]);
for(int l = 1; l < len; l <<= 1) {
int w0 = ksm(3, (mod - 1) / (l << 1));
for(int i = 0; i < len; i += (l << 1)) {
int w = 1, a0 = i, a1 = i + l;
for(int k = 0; k < l; k++, a0++, a1++, w = 1LL * w0 * w % mod) {
int tmp = 1LL * A[a1] * w % mod;
A[a1] = ((A[a0] - tmp) % mod + mod) % mod;
A[a0] = (A[a0] + tmp) % mod;
}
}
}
if(!(~flag)) {
std::reverse(A.begin() + 1, A.end());
int inv = ksm(len, mod - 2);
for(int i = 0; i < len; i++) A[i] = 1LL * A[i] * inv % mod;
}
}
vector<int> operator * (vector<int> A, vector<int> B) {
int tot = A.size() + B.size() - 1;
for(len = 1; len <= tot; len <<= 1);
for(int i = 0; i < len; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) * (len >> 1));
FNTT(A, 1), FNTT(B, 1);
vector<int> ans;
for(int i = 0; i < len; i++) ans.push_back(1LL * A[i] * B[i] % mod);
FNTT(ans, -1);
ans.resize(tot);
return ans;
}
vector<int> operator - (const vector<int> &A, const vector<int> &B) {
vector<int> ans;
for(int i = 0; i < (int)std::min(A.size(), B.size()); i++) ans.push_back(A[i] - B[i]);
for(int i = B.size(); i < (int)A.size(); i++) ans.push_back(A[i]);
for(int i = A.size(); i < (int)B.size(); i++) ans.push_back(-B[i]);
return ans;
}
vector<int> inv(const vector<int> &A) {
if(A.size() == 1) {
vector<int> ans;
ans.push_back(ksm(A[0], mod - 2));
return ans;
}
int n = A.size(), _ = (n + 1) >> 1;
vector<int> B = A, ans;
B.resize(_);
B = inv(B);
ans.push_back(2);
ans = B * (ans - A * B);
ans.resize(n);
return ans;
}
vector<int> getd(const vector<int> &A) {
vector<int> ans;
ans.resize(A.size() - 1);
for(int i = 1; i < (int)A.size(); i++) ans[i - 1] = 1LL * i * A[i] % mod;
return ans;
}
vector<int> geti(const vector<int> &A) {
vector<int> ans;
ans.resize(A.size() + 1);
for(int i = 1; i < (int)ans.size(); i++) ans[i] = 1LL * A[i - 1] * ksm(i, mod - 2) % mod;
return ans;
}
vector<int> ln(const vector<int> &A) {
vector<int> B = getd(A), C = inv(A);
return geti(B * C);
}
int main() {
int n = in();
vector<int> a;
static int fac[maxn];
fac[0] = 1;
for(int i = 1; i <= n; i++) fac[i] = 1LL * fac[i - 1] * i % mod;
for(int i = 0; i <= n; i++) a.push_back(1LL * ksm(2, (((LL)i * (i - 1)) / 2)) * ksm(fac[i], mod - 2) % mod);
a = ln(a);
printf("%d\n", (int)(1LL * a[n] * fac[n] % mod));
return 0; }

最新文章

  1. [MySQL]使用Begin...End语句的一个坑
  2. linux 下查mac
  3. php使用openssl来实现RSA(非对称加密)
  4. OutOfMemoryError异常穷举
  5. oracle知识点
  6. 李洪强iOS开发之后使用XIB实现横向滚动的UIScrollView
  7. Index of super-prime - SGU 116(素数+背包)
  8. Unreal Engine 4 创建Destructible Mesh(可破坏网格)
  9. 序列化为XML
  10. MyCat分片规则--笔记(二)
  11. 关于PHP创建接口及调用接口的简短例子(本地)
  12. cocos2dx 实现gpu instancing
  13. ASP.NET Core 微服务初探[2]:熔断降级之Polly
  14. Java后端工程师必备书单(含大后端方向相关书籍)
  15. 『TensorFlow』读书笔记_Inception_V3_下
  16. centos7下安装docker(12docker网络)
  17. 在ASP.Net环境中,当用户点击报表中的超链接时如何调用Java Script方法?
  18. Devops 到底是什么?(转)
  19. WorldWind源码剖析系列:下载请求类DownloadRequest
  20. [Practical.Vim(2012.9)].Drew.Neil.Tip21学习摘要

热门文章

  1. spring学习六
  2. 线程安全(1)--demo1
  3. SUSE 安装mysql
  4. 第十七章 Velocity优化实践(待续)
  5. 11-09SQLserver 基础-数据库之汇总练习45题
  6. LNMP 1.1 php编译安装
  7. JS中,根据div数值判断弹出窗口
  8. strcmp()比较函数和strcasecmp()和strnatcmp()
  9. repeater的command事件用法
  10. easyui layout 折叠之后显示标题