Repeatless Numbers[POJ2956]
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 1719 | Accepted: 726 |
Description
A repeatless number is a positive integer containing no repeated digits. For instance, the first 25 repeatless numbers are
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, …
Given an integer n, your goal is to compute the nth repeatless number.
Input
The input test file will contain multiple test cases, each consisting of a single line containing the integer n, where 1 ≤ n ≤ 1000000. The end-of-file is marked by a test case with n = 0 and should not be processed.
Output
For each input case, the program should print the nth repeatless number on a single line.
Sample Input
25
10000
0
Sample Output
27
26057
Source
#include<stdio.h>
#include<string.h>
int f[];
int T=-;
int s[];
int d[];
int sum=;
void dfs(int dep)
{
int i;
if (dep==)
{
int tmp=d[];
for (i=;i<=;i++) tmp=tmp*+d[i];
T++;
f[T]=tmp;
return;
}
if (T>) return;
for (i=;i<=;i++)
if (s[i]==)
{
d[dep+]=i;
sum+=i;
if (sum) s[i]++;
dfs(dep+);
if (sum) s[i]--;
sum-=i;
}
}
void prepare()
{
memset(s,,sizeof(s));
dfs();
}
int main()
{
prepare();
int N;
while (scanf("%d",&N)!=EOF && N) printf("%d\n",f[N]);
return ;
}
Repeatless Numbers[POJ2956]的更多相关文章
- poj2956 Repeatless Numbers(枚举|BFS)
题目链接 http://poj.org/problem?id=2956 题意 如果一个数中的每一位都是不同的,那么这个数叫做无重复数,如11是有重复数,12是无重复数.输入正整数n(1<=n&l ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- Soj题目分类
-----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
随机推荐
- 用Prime31实现Google Play In-App-Blling
Android开发者想在海外赚钱,接入Google Play是不二选择,然而一堆英文文档对于像我这样的英语四级都木有过的可谓是苦恼之极.近段时间因工作需要研究了Unity接入Google Play的整 ...
- 详解HttpURLConnection
请求响应流程 设置连接参数的方法 setAllowUserInteraction setDoInput setDoOutput setIfModifiedSince setUseCaches setD ...
- SQL面试积累
以下题目都在MySQL上测试可行,有疏漏或有更优化的解决方法的话欢迎大家提出,我会持续更新的:) 有三个表,如果学生缺考,那么在成绩表中就不存在这个学生的这门课程成绩的记录,写一段SQL语句,检索出每 ...
- (转)女生应该找一个玩ACM的男生
1.强烈的事业心 将来,他也一定会有自己热爱的事业.而且,男人最性感的时刻之一,就是他专心致志做事的时候.所以,找一个机会在他全神贯注玩ACM的时候,从侧面好好观察他,你就会发现我说的话没错. 2.永 ...
- openstack 前期准备工作
OS 是 centos6.5_X86_64 一.vmware 虚拟机 准备两台机虚拟机即可 二.导入第三方安装源 [root@openstack ~]# rpm -Uvh http://dl.fedo ...
- [ruby on rails] 跟我学之(6)显示指定数据
根据<[ruby on rails] 跟我学之路由映射>,我们知道,可以访问 GET /posts/:id(.:format) 来显示具体的对象. 1. 修改action 修改 ap ...
- XPath学习:轴(3)——descendant
XPath 是一门在 XML 文档中查找信息的语言.XPath 可用来在 XML 文档中对元素和属性进行遍历. XPath 是 W3C XSLT 标准的主要元素,并且 XQuery 和 XPointe ...
- Effecvtive C++笔记:让自己习惯C++
条款01:视C++为一个语言联绑 C++的四个语言层次: C:C++是以C为基础的.基本数据类型.语句.预处理器.数组.指针等统统来自C. Oject-Oriented C++:面向对象这一特性包含了 ...
- Java for LeetCode 151 Reverse Words in a String
Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...
- codeforces B. Eight Point Sets 解题报告
题目链接:http://codeforces.com/problemset/problem/334/B 一开始看到题目,有点怯,理解了题目后,其实并不难.这句话是突破口 three distinct ...