细心点想,就明白了,题目是求和为N的各数的最小公倍数的种数。其实就是求N以内的各素数的不同的组合(包含他们的次方),当然,是不能超过N的。用Dp能解决。和背包差不多。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define N 1010
#define LL __int64
using namespace std; LL dp[N]; int prim[N],np;
bool isprime[N]; void init(){
np=;
memset(isprime,true,sizeof(isprime));
for(int i=;i<N;i++){
if(isprime[i]){
prim[++np]=i;
for(int j=i*i;j<N;j+=i)
isprime[j]=false;
}
}
} int main(){
init();
int n,tmp;
while(scanf("%d",&n)!=EOF){
for(int i=;i<=n;i++)
dp[i]=1LL;
bool flag=false;
for(int k=;k<=np;k++){
if(prim[k]>n) break;
for(int i=n;i>=;i--){
tmp=prim[k];
while(i-tmp>=){
dp[i]+=dp[i-tmp];
tmp*=prim[k];
}
}
}
printf("%I64d\n",dp[n]);
}
return ;
}

HDU 4345的更多相关文章

  1. HDU 4345 Permutation dp

    Permutation Problem Description There is an arrangement of N numbers and a permutation relation that ...

  2. hdu 4345 Permutation 记忆化搜索

    思路:实际上求的是和小于等于n的质数的种类数!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorit ...

  3. 【HDU - 4345 】Permutation(DP)

    BUPT2017 wintertraining(15) #8F 题意 1到n的排列,经过几次置换(也是一个排列)回到原来的排列,就是循环了. 现在给n(<=1000),求循环周期的所有可能数. ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. luogu3865 【模板】 ST表

    题目大意:给出一段序列,每次查询一段区间,求区间最大值. ST表:设原序列为A,定义F[i][k]为A[i][2k-1]的最大值.有递归式:F[i][k]=max(F[i][k-1], F[i+2k- ...

  2. 利用jquery的ajaxPrefilter阻止重复发送请求

    利用jquery的ajaxPrefilter阻止重复发送请求 (function ($) { var pendingRequests = {}; // 所有ajax请求的通用前置filter $.aj ...

  3. [Codeforces]Codeforces Round #460 (Div. 2)

    Supermarket 找最便宜的就行 Solution Perfect Number 暴力做 Solution Seat Arrangement 注意当k=1时,横着和竖着是同一种方案 Soluti ...

  4. canvas动画简单操作

    canvas动画 小球滚动效果 关键api: window.requestAnimationFrame(draw) 会递归调用draw函数,替代setInterval var x = 20; var ...

  5. (转)redux

    随着 JavaScript 单页应用开发日趋复杂,越来越多的 state (状态)需要在前端进行管理. 这些 state 可能包括服务器响应.缓存数据.本地生成尚未持久化到服务器的数据,也包括 UI ...

  6. 【Oracle】创建概要文件

    任务1:创建profile 创建概要文件my_profile 1)密码复杂性要求:启用: 2)密码长度最小值:8位: 3)密码错误输入三次,锁定账户,2分钟后自动解锁 --创建密码复杂度校验函数 @? ...

  7. sql多表关联

    inner join(等值连接) 只返回两个表中联结字段相等的行 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有 ...

  8. 写给VC++ Windows开发的初学者 一片不错的博文

    不知不觉2010年都过了半年了,想来我学C语言已经12个年头了(从1998年开始),用VC++也有11年了,最早使用Turbo C2.0 ,也学过汇编,后来使用Borland C++3.0 .Micr ...

  9. ubuntu 安装 OpenCV-CUDA

    参考链接:http://www.cnblogs.com/platero/p/3993877.html 官方指导:https://help.ubuntu.com/community/OpenCV 0.这 ...

  10. SVN冲突出现原因及解决方法浅谈

    缘由 很简单,用svn合base,出现了各种各样奇怪的问题,虽然最终没有造成什么大的线上问题,但过程也是曲折的,耗费个人精力,也占用他人资源,不好不好,一点都不佛系. 究其原因,还是对为什么出现各种冲 ...