http://www.lydsy.com/JudgeOnline/problem.php?id=1025

首先根据置换群可得

$$排数=lcm\{A_i, A_i表示循环节长度\}, \sum_{i=1}^{k} A_i = n$$

根据lcm的定义,分解质因数拆掉$A_i=p_1^{x_1} \times p_2^{x_2} \times ... \times p_k^{x_k}$后

$$lcm=\prod_{i} p_i^{max\{x_i\}}$$

所以我们只看$max\{x_i\}$即可,即忽略掉$\le max\{x_i\}$的其它因子。所以问题等价于:

$$\sum_{i} p_i^{x_i} \le n$$

的方案数。

然后随便dp即可

设$d(i,j)$表示前$i$个质数和为$j$的方案,有

$$d(i,j)=d(i-1,j)+\sum_{k} d(i-1, j-p_i^k) $$

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mkpii make_pair<int, int>
#define pdi pair<double, int>
#define mkpdi make_pair<double, int>
#define pli pair<ll, int>
#define mkpli make_pair<ll, int>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=1005;
int p[N], vis[N], cnt, n;
ll d[2][N];
void init() {
for1(i, 2, n) {
if(!vis[i]) p[++cnt]=i;
for(int j=1; j<=cnt && p[j]*i<=n; ++j) {
vis[p[j]*i]=1;
if(!(i%p[j])) break;
}
}
} int main() {
read(n); init();
int now=1, last=0;
d[last][0]=1;
for1(i, 1, cnt) {
for1(j, 0, n) {
d[now][j]=d[last][j];
for(int k=p[i]; j-k>=0; k*=p[i])
d[now][j]+=d[last][j-k];
}
for1(j, 0, n) d[last][j]=0;
now^=1;
last^=1;
}
ll ans=0;
for1(i, 0, n) ans+=d[last][i];
printf("%lld", ans);
return 0;
}

Description

windy学会了一种游戏。对于1到N这N个数字,都有唯一且不同的1到N的数字与之对应。最开始windy把数字按顺序1,2,3,……,N写一排在纸上。然后再在这一排下面写上它们对应的数字。然后又在新的一排下面写上它们对应的数字。如此反复,直到序列再次变为1,2,3,……,N。 如: 1 2 3 4 5 6 对应的关系为 1->2 2->3 3->1 4->5 5->4 6->6 windy的操作如下 1 2 3 4 5 6 2 3 1 5 4 6 3 1 2 4 5 6 1 2 3 5 4 6 2 3 1 4 5 6 3 1 2 5 4 6 1 2 3 4 5 6 这时,我们就有若干排1到N的排列,上例中有7排。现在windy想知道,对于所有可能的对应关系,有多少种可能的排数。

Input

包含一个整数,N。

Output

包含一个整数,可能的排数。

Sample Input

【输入样例一】
3
【输入样例二】
10

Sample Output

【输出样例一】
3
【输出样例二】
16

HINT

【数据规模和约定】

100%的数据,满足 1 <= N <= 1000 。

Source

 

【BZOJ】1025: [SCOI2009]游戏(置换群+dp+特殊的技巧+lcm)的更多相关文章

  1. BZOJ 1025: [SCOI2009]游戏 [置换群 DP]

    传送门 题意:求$n$个数组成的排列变为升序有多少种不同的步数 步数就是循环长度的$lcm$..... 那么就是求$n$划分成一些数几种不同的$lcm$咯 然后我太弱了这种$DP$都想不出来.... ...

  2. BZOJ 1025: [SCOI2009]游戏( 背包dp )

    显然题目要求长度为n的置换中各个循环长度的lcm有多少种情况. 判断一个数m是否是满足题意的lcm. m = ∏ piai, 当∑piai ≤ n时是满足题意的. 最简单我们令循环长度分别为piai, ...

  3. [BZOJ 1025] [SCOI2009] 游戏 【DP】

    题目链接:BZOJ - 1025 题目分析 显然的是,题目所要求的是所有置换的每个循环节长度最小公倍数的可能的种类数. 一个置换,可以看成是一个有向图,每个点的出度和入度都是1,这样整个图就是由若干个 ...

  4. [bzoj 1025][SCOI2009]游戏(DP)

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1025 分析:首先这个问题等价于A1+A2+……Ak=n,求lcm(A1,A2,……,Ak)的种 ...

  5. BZOJ 1025 [SCOI2009]游戏

    1025: [SCOI2009]游戏 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1533  Solved: 964[Submit][Status][ ...

  6. bzoj 1025 [SCOI2009]游戏(置换群,DP)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1025 [题意] 给定n,问1..n在不同的置换下变回原序列需要的不同排数有多少种. [ ...

  7. BZOJ 1025 [SCOI2009]游戏 (DP+分解质因子)

    题意: 若$a_1+a_2+\cdots+a_h=n$(任意h<=n),求$lcm(a_i)$的种类数 思路: 设$lcm(a_i)=x$, 由唯一分解定理,$x=p_1^{m_1}+p_2^{ ...

  8. bzoj 1025: [SCOI2009]游戏【数学+dp】

    很容易发现行数就是lcm环长,也就是要求和为n的若干数lcm的个数 有结论若p1^a1+p2^a2+...+pm^am<=n,则ans=p1^a1p2^a2..*pm^am是n的一个可行答案.( ...

  9. BZOJ 1025 SCOI2009 游戏 动态规划

    标题效果:特定n.行定义一个替代品1~n这种更换周期发生后,T次要(T>0)返回到原来的顺序 找到行的所有可能的数 循环置换分解成若干个,然后行位移数是这些周期的长度的最小公倍数 因此,对于一些 ...

随机推荐

  1. js与jQuery方法对比

      javascript与jQuery方法对比jquery对象转dom对象 // 方式一(推荐使用) $("input")[0] // 方式二 $("input" ...

  2. 19-spring学习-springMVC环境配置

    新建一共环境,添加spring支持,就可以开发springMVC了. 既然是springMVC,就必须为其定义相关配置. 1,springMVC所有配置都需要在applicationContext.x ...

  3. C#指南,重温基础,展望远方!(10)C#枚举

    枚举类型是包含一组已命名常量的独特值类型. 需要定义包含一组离散值的类型时,可以定义枚举. 枚举使用一种整型值类型作为其基础存储, 并提供离散值的语义含义. 以下示例声明并使用名为“Color”的 e ...

  4. 使用maven开发OSGI样例

    一:创建maven项目,在pom.xml里面增加例如以下依赖 <dependency> <groupId>org.osgi</groupId> <artifa ...

  5. 使用TestFlight邀请外部人员測试APP

    怎样使用TestFlight邀请外部人员測试APP 详细过程例如以下: 1.在邀请測试人员的时候.按上线流程打包APP,提交. 2.提交审核,在邀请測试员的时候,你必须先提交审核,苹果会在大约2个工作 ...

  6. oracle 错误码查看命令oerr ora及常用错误码总结--不断更新

    oracle 错误码查看命令oerr ora及常用错误码总结--不断更新 1.ORA-00907: 缺失右括号 我自己的问题出在 字段的default 和 not null 顺序反了,defalut ...

  7. linux CentOs 权限导致的Apache - "DocumentRoot must be a directory"的解决方案

    在配置apache服务时经常遇到DocumentRoot must be a directory的错误提示,刚接触到apache时折腾了几个小时才找到错误的原因,出现这样的错误一般都是由于selinu ...

  8. Atitit.mysql oracle with as模式临时表模式 CTE 语句的使用,减少子查询的结构性 mssql sql server..

    Atitit.mysql  oracle with as模式临时表模式 CTE 语句的使用,减少子查询的结构性 mssql sql server.. 1. with ... as (...) 在mys ...

  9. FPGA设计经验谈 —— 10年FPGA开发经验的工程师肺腑之言

    FPGA设计经验谈 —— 10年FPGA开发经验的工程师肺腑之言 2014年08月08日 14:08    看门狗 关键词: FPGA 作者:friends 从大学时代第一次接触FPGA至今已有10多 ...

  10. 关于 initWithNibName 和 loadNibNamed 的区别和联系-iPhone成长之路

    转自:http://blog.sina.com.cn/s/blog_7b9d64af01018f2u.html 关于 initWithNibName 和 loadNibNamed 的区别和联系.之所以 ...