hdu-acm stepsHumble Numbers
这是我做的第六道动态规划水题,对动态规划差不多有了一个大致的概念。动态规划有几个关键因素,第一是最优子结构,第二是状态和状态转移方程。整个过程都是以 最优 为中心的。因此在状态转移方程中常涉及到几个子状态的最优化的判断。这道题既采用了递堆的思想,又采用了一点动态规划的思想。状态转移方程为:f[i]=min{2*f[p],3*f[q],5*f[r],7*f[s]};
#include"iostream"
#include"stdio.h"
#include"algorithm"
#include"string.h"
#include"cmath"
#include"ctype.h"
#define mx 10005
using namespace std;
long long dp[mx];
int p,q,r,s;
int min(int a,int b,int c,int d)
{
int mi=a;
if(b<mi) mi=b;
if(c<mi) mi=c;
if(d<mi) mi=d; if(a==mi) p++;
if(b==mi) q++;
if(c==mi) r++;
if(d==mi) s++; return mi;
}
int main()
{
int i,n;
dp[]=;
p=q=r=s=;
for(i=;i<=;i++)
{
dp[i]=min(*dp[p],*dp[q],*dp[r],*dp[s]);
}
while(cin>>n,n)
{
if(n%==&&n%!=) cout<<"The "<<n<<"st humble number is "<<dp[n]<<"."<<endl;
else if(n%==&&n%!=) cout<<"The "<<n<<"nd humble number is "<<dp[n]<<"."<<endl;
else if(n%==&&n%!=) cout<<"The "<<n<<"rd humble number is "<<dp[n]<<"."<<endl;
else cout<<"The "<<n<<"th humble number is "<<dp[n]<<"."<<endl;
}
return ;
}
hdu-acm stepsHumble Numbers的更多相关文章
- HDU 3117 Fibonacci Numbers(围绕四个租赁斐波那契,通过计++乘坐高速动力矩阵)
HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵高速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意: 求第n个斐波那契数的 ...
- hdu acm 1028 数字拆分Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- 【数位DP】 HDU 4722 Good Numbers
原题直通车: HDU 4722 Good Numbers 题意: 求区间[a,b]中各位数和mod 10==0的个数. 代码: #include<iostream> #include& ...
- HDOJ(HDU).1058 Humble Numbers (DP)
HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2 ...
- hdu 3117 Fibonacci Numbers 矩阵快速幂+公式
斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...
- HDU 4722 Good Numbers(位数DP)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)
Description If we sum up every digit of a number and the result can be exactly divided by 10, we say ...
- HDU 4722 Good Numbers
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722 Good Numbers Time Limit: 2000/1000 MS (Java/Othe ...
- hdu acm 1166 敌兵布阵 (线段树)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- hdu acm 2082 找单词
找单词 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 1058 Humble Numbers(离线打表)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1058 解题报告:输入一个n,输出第n个质因子只有2,3,5,7的数. 用了离线打表,因为n最大只有58 ...
随机推荐
- Apache配置文件中的deny和allow的使用
Apache配置文件中的deny和allow的使用 由于产品的需要,最近在配置apache的负载均衡功能,但是在配置虚拟主机的访问权限的时候我们遇到了一些问题.主要问题是deny和allow的执行顺序 ...
- Select Top在不同数据库中的使用
1. oracle数据库 SELECT * FROM TABLE1 WHERE ROWNUM<=N 2. Infomix数据库 SELECT FIRST N * FROM TABLE1 3. D ...
- 集群ssh服务和免密码登录的配置
安装Hadoop之前,由于集群中大量主机进行分布式计算需要相互进行数据通信,服务器之间的连接需要通过ssh来进行,所以要安装ssh服务,默认情况下通过ssh登录服务器需要输入用户名和密码进行连接,如果 ...
- POJ 1006 - Biorhythms (中国剩余定理)
B - Biorhythms Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Subm ...
- iOS开发——开发实战篇&版本控制SVN和Git使用详解
版本控制SVN和Git使用详解 公司的实际开发中,在天朝使用较多的还是SVN,因为SVN是集中式的,在天朝上班你们都懂的! -----------------svn--------- ...
- July 15th, Week 29th Friday, 2016
A book is a gift that you can open again and again. 书是你可以一次又一次打开的礼物. Some gifts are born with you, a ...
- cenos配置
#修复ifconfig1.查看 /sbin/ifconfig是否存在 echo $PATH2.查看ifconfig命令是否存在ls /sbin |grep ifconfig如果ifconfig命令存在 ...
- RedHat中敲sh-copy-id命令报错:-bash: ssh-copy-id: command not found
RedHat中敲sh-copy-id命令报错:-bash: ssh-copy-id: command not found 在多台Linux服务器SSH相互访问无需密码, 其中进入一台Linus中,对其 ...
- C#的面向对象特性之封装
在C#语言中,共有五种访问修饰符:public.private.protected.internal.protected internal. public 公有访问.不受任何限制.private 私有 ...
- 网页中meta标记
网页中常常看见有这样的标记,他们是清浏览器缓存用的 <meta http-equiv="> PS:清除浏览器中的缓存,它和其它几句合起来用,就可以使你再次进入曾经访问过的页 ...