题意:

若$a_1+a_2+\cdots+a_h=n$(任意h<=n),求$lcm(a_i)$的种类数

思路:

设$lcm(a_i)=x$,

由唯一分解定理,$x=p_1^{m_1}+p_2^{m_2}+\cdots+p_{tot}^{m_{tot}}$

设$b_i=p_i^{m_i}$,

则能组成x的和最小的数为$\sum p_i^{m_i}$

所以只要$\sum p_i^{m_i}\leq n$即可,

其中小于的时候,剩余补1即可

dp[i][j]表示选了前i个素数,他们的和为j时的方法数

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e3+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); int n, tot;
int prime[ + ];
int vis[ + ];
ll ans, dp[ +][ + ];
int main(){
scanf("%d", &n);
tot = ;
for(int i = ; i <= ; i++){
if(!vis[i])prime[++tot] = i;
for(int j = ; j <= tot && i *prime[j] <= ; j++){
vis[i*prime[j]] = ;
if(i%prime[j]==)break;
}
}
dp[][] = ;
for(int i = ; i <= tot; i++){
for(int j = ; j <= n; j++)dp[i][j] = dp[i-][j];
for(int j = prime[i]; j <= n; j *= prime[i]){
for(int k = ; k + j <= n; k++){
dp[i][k+j] += dp[i-][k];
}
}
}
ans = ;
for(int i = ; i <= n; i++)ans+=dp[tot][i];
printf("%lld", ans);
return ;
}

BZOJ 1025 [SCOI2009]游戏 (DP+分解质因子)的更多相关文章

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

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

  2. BZOJ 1025 [SCOI2009]游戏

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

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

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

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

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

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

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

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

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

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

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

  8. BZOJ 1025 SCOI2009 游戏 动态规划

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

  9. UVA 10780 Again Prime? No Time. 分解质因子

    The problem statement is very easy. Given a number n you have to determine the largest power of m,no ...

随机推荐

  1. Linux安装MySQL及基本操作(Centos)

    安装: 系统:CentOS-7-x86_64-DVD-1810.iso 安装命令: wget http://repo.mysql.com/mysql-community-release-el7-5.n ...

  2. shiro整合springmvc

    说明   代码及部分相关资料根据慕课网Mark老师的视频进行整理   其他资料: shiro官网 流程 配置 1) 配置web.xml整合shiro 把shiro整合到springMVC实质上是在we ...

  3. linux各目录及重要目录的详细介绍

    1 目录说明 根目录 (/) /bin bin是Binary的缩写, 这个目录存放着最经常使用的命令,比如ls,cat,mkdir等 /dev dev是Device(设备)的缩写, 该目录下存放的是L ...

  4. POJ 2318 TOYS(叉积+二分)

    题目传送门:POJ 2318 TOYS Description Calculate the number of toys that land in each bin of a partitioned ...

  5. Linux学习_菜鸟教程_3

    我是在UBANTO上运行Linux的,开机启动时按下shift或者Esc都不能进入到grub,没有百度到可靠的教程. 暂时先这样吧.免得我把系统搞坏了,先学点实用的知识~~ Next Chapter

  6. Spring Cloud Alibaba Nacos

    1. Spring Cloud Alibaba 介绍 Spring Cloud Alibaba 为分布式应用程序开发提供了一站式解决方案.它包含了开发分布式应用程序所需的所有组件,使得你可以轻松地使用 ...

  7. MySQL定时备份(全量备份+增量备份)

    MySQL 定时备份 参考 zone7_ 的 实战-MySQL定时备份系列文章 参考 zmcyu 的 mysql数据库的完整备份.差异备份.增量备份 更多binlog的学习参考马丁传奇的 MySQL的 ...

  8. LCA - 求任意两点间的距离

    There are n houses in the village and some bidirectional roads connecting them. Every day peole alwa ...

  9. Nginx作为静态web服务器——缓存原理

    浏览器缓存 ​ 客户端无缓存的情况下 ​ 客户端有缓存的情况下 ​ 校验过期机制 ​ 本地客户端会检查Cache-Control(max-age)缓存是否过期,(max-age)为过期时间 Last- ...

  10. BeautifulSoup的简单用法

    官方文档加载比较慢(估计是我党的原因) https://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html#find-parents ...