P-Function
题意:
对于集合 $S = {1, 2, ...., n}$ , 定义函数 $F(x) = y, x, y$ 属于 $S$,对于任何 $x$ 属于 $S$,
有 $F(F...F(x)) = x$, $F$ 出现了 $K$ 次,则这个函数为 $P-function$,问 $P-function$ 的数量。
解法:
注意到 $P-function$ 实质上是 一个 $1$ ~ $n$ 的置换,对于该置换中的所有循环,有 $length | K$。
考虑dp,
$f(i, j)$ 表示考虑前 $i$ 个 $K$ 的因数,确定了 $j$ 个元素的循环形状的方案数。
假定当前循环长度为 $d$,这样考虑每一次决定好 当前剩余最小元素所在的循环。
这样有:
$f(i,j) = \sum{ f(i-1, j-d) C_{j-1}^{d-1} (d-1)!}$
应用滚动数组,复杂度$O(n \sqrt n)$
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>>
#include <algorithm> #define N 20010
#define P 1000000007LL
#define LL long long using namespace std; LL inv[N], f[N], fac[N], rfac[N];
vector<int> Div; LL qpow(LL x,int n)
{
LL ans = ;
for(;n;n >>= , x = x * x % P)
if(n & ) ans = ans * x % P;
return ans;
} LL comb(int n, int m)
{
if(n < m) return ;
return fac[n] * rfac[n-m] %P * rfac[m] %P;
} int main()
{
inv[] = ;
fac[] = ;
rfac[] = ;
for(int i = ;i < N;i++)
{
fac[i] = fac[i-] * i % P;
inv[i] = qpow(i, P-);
rfac[i] = qpow(fac[i], P-);
}
int T, n, K;
cin >> T;
while(T--)
{
cin >> n >> K;
Div.clear();
for(int i = ;i*i <= K;i++)
if(K % i == )
{
Div.push_back(i);
if(i * i != K) Div.push_back(K / i);
}
sort(Div.begin(),Div.end());
f[] = 1LL;
for(int i = ;i <= n;i++)
{
f[i] = ;
for(int j = ;j < (int)Div.size() && Div[j] <= i;j++)
f[i] += f[i - Div[j]] * comb(i - , Div[j] - ) %P * fac[Div[j]-] %P;
f[i] %= P;
}
cout << f[n] << endl;
}
return ;
}
P-Function的更多相关文章
- 通过百度echarts实现数据图表展示功能
现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解 ...
- jsp中出现onclick函数提示Cannot return from outside a function or method
在使用Myeclipse10部署完项目后,原先不出错的项目,会有红色的叉叉,JSP页面会提示onclick函数错误 Cannot return from outside a function or m ...
- JavaScript function函数种类
本篇主要介绍普通函数.匿名函数.闭包函数 目录 1. 普通函数:介绍普通函数的特性:同名覆盖.arguments对象.默认返回值等. 2. 匿名函数:介绍匿名函数的特性:变量匿名函数.无名称匿名函数. ...
- 在ubuntu16.10 PHP测试连接MySQL中出现Call to undefined function: mysql_connect()
1.问题: 测试php7.0 链接mysql数据库的时候发生错误: Fatal error: Uncaught Error: Call to undefined function mysqli_con ...
- jquery中的$(document).ready(function() {});
当文档载入时执行function函数里的代码, 这部分代码主要声明,页面加载后 "监听事件" 的方法.例如: $(document).ready( $("a") ...
- Function.prototype.toString 的使用技巧
Function.prototype.toString这个原型方法可以帮助你获得函数的源代码, 比如: function hello ( msg ){ console.log("hello& ...
- 转:ORA-15186: ASMLIB error function = [asm_open], error = [1], 2009-05-24 13:57:38
转:ORA-15186: ASMLIB error function = [asm_open], error = [1], 2009-05-24 13:57:38http://space.itpub. ...
- [Xamarin] 透過Native Code呼叫 JavaScript function (转帖)
今天我們來聊聊關於如何使用WebView 中的Javascript 來呼叫 Native Code 的部分 首先,你得先來看看這篇[Xamarin] 使用Webview 來做APP因為這篇文章至少講解 ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- javascript中的Function和Object
写的很好,理解了很多,特此转发记录 转自:http://blog.csdn.net/tom_221x/archive/2010/02/22/5316675.aspx 在JavaScript中所有的对象 ...
随机推荐
- 《UNIX-Shell编程24学时教程》读书笔记Chap3,4 文件,目录操作
Chap3 文件操作 P28 在这章中,要着重记住一些常用的选项,要有使用正则表达式的思维,能更快达到目的.----@im天行 3.1 列文件名 .profile sh的初始化脚本: .kshr ...
- MySQL 下优化SQL语句的一些经验
http://java-guru.iteye.com/blog/143377
- POJ 2480 Longge's problem 积性函数
题目来源:id=2480" style="color:rgb(106,57,6); text-decoration:none">POJ 2480 Longge's ...
- Install Server Backup Manager on CentOS, RHE, and Fedora
Skip to end of metadata Added by Internal, last edited by Internal on Aug 25, 2014 Go to start of me ...
- gridcontrol复选框功能实现(超具体)
博主这几天就准备离职了,以后不再做.Net开发.因此这应该是我写的最后一篇关于dev控件的博文.既然是最后一篇,那就写的具体一些.画个圆满的省略号...... 本文介绍gridcontrol怎样实现复 ...
- mysql could not be resolved: Name or service not known
问题: mysql DNS反解:skip-name-resolve 错误日志有类似警告: 1.120119 16:26:04 [Warning] IP address '192.168.1.10' c ...
- kubernetes-handbook 阅读笔记
文档地址 https://jimmysong.io/kubernetes-handbook/concepts/ Pod是在Kubernetes集群中运行部署应用或服务的最小单元,它是可以支持多容器的. ...
- 无感知的用同步的代码编写方式达到异步IO的效果和性能,避免了传统异步回调所带来的离散的代码逻辑和陷入多层回调中导致代码无法维护
golang/goroutine 和 swoole/coroutine 协程性能测试对比 - Go语言中文网 - Golang中文社区 https://studygolang.com/articles ...
- cenos 6.5 安装apache 2.4.28出现种问题
编译出错 configure: error: APR-util not found. Please read the documentation 解决办法 wget http://apache.fre ...
- CRM 安装不规范,亲人两行泪
安装CRM需要严格按照CRM部署文档的要求进行,比如设置CRM服务的服务账号一定要加入到CRM所在组织库用户里,不然会遇到下面错误.这个就是传递到SQL 的账号,在SQL那边不识别 <s:Env ...