Epic - Desirable Number
A number is called 'desirable' if all thedigits are strictly ascending eg: 159 as 1<5<9. You know that your rivalhas a strictly numeric password that is 'desirable'. Your close ally has givenyou the number of digits (N) in your rival's password. WAP th\hjtat takes in'N' as input and prints out all possible 'desirable' numbers that can be formedwith N digits.
递归:参数记录剩余需要生成的长度和最小的能append的数字
def bfs(remain,start,string)
if remain == 0
@ans << string
else
(start..9).each {|i| bfs(remain-1, i+1, string + i.to_s)}
end
end def desire_number(n)
@ans = []
bfs(n,1,'')
@ans
end
循环:用两个数组分别保存i-1的情况和i的情况 i from 1 to n
def desire_number(n)
return 0 if n == 0
a = ['']
(n-1).times do
b = []
a.each {|x| (x[-1].to_i..9).each{|y| b << x+y.to_s}}
a = b
end
a
end
Epic - Desirable Number的更多相关文章
- Epic - Seed Number
Find the seed of a number. Eg : 1716 = 143*1*4*3 =1716 so 143 is the seed of 1716. find all possible ...
- Epic - Decimal Number
Let the user enter a decimal number. Therange allowed is 0.0001 to 0.9999. Only four decimal places ...
- ACM: 限时训练题解-Epic Professor-水题
Epic Professor Dr. Bahosain works as a professor of Computer Science at HU (Hadramout Universit ...
- CF Gym 100685E Epic Fail of a Genie
传送门 E. Epic Fail of a Genie time limit per test 0.5 seconds memory limit per test 64 megabytes input ...
- Codeforces gym 100685 E. Epic Fail of a Genie 贪心
E. Epic Fail of a GenieTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685 ...
- MapReduce: number of mappers/reducers
14 down vote It's the other way round. Number of mappers is decided based on the number of splits. I ...
- How to create functions that can accept variable number of parameters such as Format
http://www.chami.com/tips/delphi/112696D.html Sometimes it's necessary to pass undefined number of [ ...
- JavaScript Math和Number对象
目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
随机推荐
- 从客户端中检测到有潜在危险的Request.Form值 的解决方法
在提交表单时候,asp.net 提示:"从客户端(......)中检测到有潜在危险的 Request.Form 值" .asp.net中的请求验证特性提供了某一等级的保护措施防止X ...
- lucene.net helper类 【结合盘古分词进行搜索的小例子(分页功能)】
转自:http://blog.csdn.net/pukuimin1226/article/details/17558247 添加:2013-12-25 更新:2013-12-26 新增分页功能. ...
- BOOST的AUTO link机制以及配置
我们在使用BOOST的时候,如果需要链接一些库,是不用我们手动去链接的,归根结底还是boost的auto_link这个机制,在boost下的auto_link.hpp这个文件夹里面,基本可以看出要根据 ...
- 嵌入式应用中CGI编程中POST、GET及环境变量详解
原载地址:http://3633188.blog.51cto.com/3623188/828095 1.POST和GET 一个CGI程序在于服务器之间的信息传输和数据传输一般通过两种方法,即 ...
- Android SDK 4.0.3 开发环境配置及运行
最近又装了一次最新版本的ADK环境 目前最新版是Android SDK 4.0.3 本文的插图和文本虽然是Android2.2的 步骤都是一样的,如果安装的过程中遇到什么问题,可以留言,我会尽快回复! ...
- activiti自定义流程之Spring整合activiti-modeler5.16实例(四):部署流程定义
注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建 (2)创建流程模型:activiti自定义流程之Spring ...
- SDS查看部署在集成TOMCAT服务器中的项目目录结构
- C++ 常见崩溃问题分析
一.前言 从事自动化测试平台开发的编程实践中,遭遇了几个程序崩溃问题,解决它们颇费了不少心思,解决过程中的曲折和彻夜的辗转反侧却历历在目,一直寻思写点东西,为这段难忘的经历留点纪念,总结惨痛的教训带来 ...
- PLSQL_性能优化工具系列16_Best Practices: Proactively Avoiding Database
占位符 PLSQL_性能优化工具系列_Best Practices: Proactively Avoiding Database/Query Performance Issue
- Report_报表中Ref Cursor数据源的概念和用法(案例)
2014-06-22 Created By BaoXinjian