bzoj1025: [SCOI2009] 游戏 6
DP。
每种排法的长度对应所有循环节长度的最小公倍数。
所以排法总数为和为n的几个数的最小公倍数的总数。
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 1000 + 10; int cnt,n;
long long f[maxn][maxn];
int prime[maxn];
bool not_prime[maxn]; void get_prime(int n) {
for(int i = 2; i <= n; i++) if(!not_prime[i]) {
prime[++cnt] = i;
for(int j = i*i; j <= n; j += i)
not_prime[j] = true;
}
} int main() {
scanf("%d",&n);
if(n == 1) printf("1\n");
else {
get_prime(n);
f[0][0] = 1;
for(int i = 1,p; i <= cnt; i++) {
p = prime[i];
memcpy(f[i],f[i-1],sizeof(f[i]));
for(;p <= n; p*=prime[i])
for(int j = p; j <= n; j++)
f[i][j] += f[i-1][j-p];
}
long long res = 0;
for(int i = 0; i <= n; i++) res += f[cnt][i];
printf("%lld\n",res);
}
return 0;
}
bzoj1025: [SCOI2009] 游戏 6的更多相关文章
- bzoj千题计划116:bzoj1025: [SCOI2009]游戏
http://www.lydsy.com/JudgeOnline/problem.php?id=1025 题目转化: 将n分为任意段,设每段的长度分别为x1,x2,…… 求lcm(xi)的个数 有一个 ...
- [BZOJ1025] [SCOI2009]游戏 解题报告
Description windy学会了一种游戏.对于1到N这N个数字,都有唯一且不同的1到N的数字与之对应.最开始windy把数字按顺序1,2,3,……,N写一排在纸上.然后再在这一排下面写上它们对 ...
- BZOJ1025: [SCOI2009]游戏
Description windy学会了一种游戏.对于1到N这N个数字,都有唯一且不同的1到N的数字与之对应.最开始windy把数字按顺序1,2,3,……,N写一排在纸上.然后再在这一排下面写上它们对 ...
- [bzoj1025][SCOI2009]游戏 (分组背包)
Description windy学会了一种游戏.对于1到N这N个数字,都有唯一 且不同的1到N的数字与之对应.最开始windy把数字按顺序1,2,3,……,N写一排在纸上.然后再在这一排下面写上它们 ...
- BZOJ1025 [SCOI2009]游戏 【置换群 + 背包dp】
题目链接 BZOJ1025 题解 题意就是问一个\(1....n\)的排列在同一个置换不断重复下回到\(1...n\)可能需要的次数的个数 和置换群也没太大关系 我们只需知道同一个置换不断重复,实际上 ...
- 2018.09.02 bzoj1025: [SCOI2009]游戏(计数dp+线筛预处理)
传送门 要将所有置换变成一个轮换,显然轮换的周期是所有置换长度的最小公倍数. 于是我们只需要求长度不超过n,且长度最小公倍数为t的不同置换数. 而我们知道,lcm只跟所有素数的最高位有关. 因此lcm ...
- bzoj1025(SCOI2009)游戏——唯一分解的思路与应用
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1025 可以认为对应的值之间连边,就连成了一个有一个或几个环的图.列数就是每个环里点数的lcm ...
- bzoj1025: [SCOI2009]游戏(DP)
题目大意:将长度为n的排列作为1,2,3,...,n的置换,有可能置换x次之后,序列又回到了1,2,3,...,n,求所有可能的x的个数. 看见这种一脸懵逼的题第一要务当然是简化题意...我们可以发现 ...
- bzoj1025 [SCOI2009]游戏——因数DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1025 这篇博客写得真好呢:https://www.cnblogs.com/phile/p/4 ...
随机推荐
- 写文件前, 检查目录写权限(PHP)
写文件前, 检查目录写权限 写或保存文件前, 确保目录是可写的, 假如不可写, 输出错误信息. 这会节约你很多调试时间. linux系统中, 需要处理权限, 目录权限不当会导致很多很多的问题, 文件也 ...
- img test
- The Black Hole of Numbers (strtoint+inttostr+sort)
For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in ...
- hdu 3518 Boring counting 后缀数组LCP
题目链接 题意:给定长度为n(n <= 1000)的只含小写字母的字符串,问字符串子串不重叠出现最少两次的不同子串个数; input: aaaa ababcabb aaaaaa # output ...
- Memcache 分布式解决方案 之 : 普通 Hash 分布
<?php /* mhash * 其实说白了,就是为了实现返回0或1 */ function mmhash($key){ $md5 = substr(md5($key),0,8);//取该字符串 ...
- C# 将datatable 转换json
public static string DataTableToJson(DataTable dt) { StringBuilder jsonBuilder = new StringBuilder() ...
- 在百万数据中找出重复的数据sql
select * from (select count(name) as isone, name from tbl_org_departments group by name) t where t.i ...
- 第二好用的时间日期选择插件(jscal)
这个是第二好用的了,支持鼠标滚动选择时间.功能很强大,文档:http://www.dynarch.com/jscal/ 效果图: <!DOCTYPE html PUBLIC ...
- NOI考前乱写
还有13天NOI,把各种乱七八糟的算法都重新过一遍还是比较有必要的... //HDU 5046 Airport //DancingLink #include<iostream> #incl ...
- Educational Codeforces Round 5 B
Problem B:http://codeforces.com/contest/616/problem/B B. Dinner with Emma 题意:一对夫妻要去餐厅吃晚饭,Emma 想去最豪华( ...