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 ...
随机推荐
- 一些LUA函数(转载)
转自http://hi.baidu.com/chevallet/item/9a3a6410c20d929198ce3363 一些LUA函数 1.assert (v [, message]) 功能:相当 ...
- 转数据库分库分表(sharding)系列(一) 拆分实施策略和示例演示
本文原文连接: http://blog.csdn.net/bluishglc/article/details/7696085 ,转载请注明出处!本文着重介绍sharding切分策略,如果你对数据库sh ...
- 如何破解excel宏的密码
http://zhidao.baidu.com/question/140107193.html 最近下载了一个excel模板,使用excel宏编的,但实际需要需更改一下,但是他设置了工作表密码保护,谁 ...
- codeforces B. Color the Fence 解题报告
题目链接:http://codeforces.com/problemset/problem/349/B 题目意思:给定v升的颜料和9个需要花费ad 升的颜料,花费ad 升的颜料意味着得到第d个数字,现 ...
- codeforces B. Jeff and Periods 解题报告
题目链接:http://codeforces.com/problemset/problem/352/B 题目意思:给出一个长度为n的序列 a1, a2, ..., an(序号i,1 <= i ...
- Codeforces Round #321 (Div. 2)C(tree dfs)
题意:给出一棵树,共有n个节点,其中根节点是Kefa的家,叶子是restaurant,a[i]....a[n]表示i节点是否有猫,问:Kefa要去restaurant并且不能连续经过m个有猫的节点有多 ...
- nginx: [warn] conflicting server name "locahost" on 0.0.0.0:80, ignored
里面域名重复: 在vhosts下多个虚拟机配置文件,都是基于域名配置的,其中两个配置文件,都起了localhost ,所以会报错!!!! 多个域名可以指向同一个目录,但同一个域名不可一指向多个目录!! ...
- Git Server & Git Hook
http://ju.outofmemory.cn/entry/16893 我喜欢 github,我现在的个人代码全部是托管在上面了,但是一些公司或者某些项目不适合放入github中,你希望能有一个完全 ...
- UML中的关联关系
UML中的关联关系其内在意思就是has a 如图: 相对于依赖关系,关联关系在代码中有所体现.上图中的关联关系在代码中体现为 其中water 中将Climate作为其中的属性. 当然,关 ...
- Android ActionBar 一步一步分析 (转)
原文摘自:http://blog.csdn.net/android2me/article/details/8874846 1.Action Bar 介绍 我们能在应用中看见的actionbar一般就是 ...