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 ...
随机推荐
- 【JAVA、C++】LeetCode 017 Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 【JAVA、C++】LeetCode 015 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...
- 11.python之线程,协程,进程,
一,进程与线程 1.什么是线程 线程是操作系统能够进行运算调度的最小单位.它被包含在进程之中,是进程中的实际运作单位.一条线程指的是进程中一个单一顺序的控制流,一个进程中可以并发多个线程,每条线程并行 ...
- codeforces B. Routine Problem 解题报告
题目链接:http://codeforces.com/problemset/problem/337/B 看到这个题目,觉得特别有意思,因为有熟悉的图片(看过的一部电影).接着让我很意外的是,在纸上比划 ...
- springMVC获取file,几种转换
//从前台通过name值获取file MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest)reque ...
- Babelfish(poj 2503)
大致题意: 输入一个字典,字典格式为“英语à外语”的一一映射关系 然后输入若干个外语单词,输出他们的 英语翻译单词,如果字典中不存在这个单词,则输出“eh” #include<iostream& ...
- 态势感知 > 技术运维问题
http://blog.csdn.net/sanmaoljh/article/details/52670226 http://u.sanwen.net/subject/250516.html http ...
- Merge和Rebase在Git中的区别
git命令Merge和Rebase的区别 git merge 会生成一个新得合并节点,而rebase不会 比如: D---E test / A---B---C---F master 使用merge合并 ...
- v4l2
参考文章:http://lwn.net/Articles/203924/ 查阅手册:https://linuxtv.org/downloads/v4l-dvb-apis/#INPUT-STATUS
- vim 多窗口
打开多个文件: 1.vim还没有启动的时候: 在终端里输入 vim file1 file2 ... filen便可以打开所有想要打开的文件 2.vim已经启动 输入 :open file 可以再打开一 ...