Repeatless Numbers
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

一开始抱着试一试的态度从小到大顺序找了一遍,不出意外地TLE了.
然后开始写dfs,还好搜索树最多10层,时间上没问题.
不过让人纠结的地方在于我从左往右搜索,当左边不存在时用来占位的0和数字真正开始后的0不好区分,比如0000000010,
其实是10,但搜索时可能会认为0之前用过.
#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]的更多相关文章

  1. poj2956 Repeatless Numbers(枚举|BFS)

    题目链接 http://poj.org/problem?id=2956 题意 如果一个数中的每一位都是不同的,那么这个数叫做无重复数,如11是有重复数,12是无重复数.输入正整数n(1<=n&l ...

  2. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  3. Soj题目分类

    -----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...

  4. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  5. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  6. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  7. [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 ...

  8. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  9. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

随机推荐

  1. [OpenJudge 3061]Flip The Card

    [OpenJudge 3061]Flip The Card 试题描述 There are N× Ncards, which form an N× Nmatrix. The cards can be p ...

  2. Android音频播放实例

    MediaPlayer: 此类适合播放较大文件,此类文件应该存储在SD卡上,而不是在资源文件里,还有此类每次只能播放一个音频文件. 1.从资源文件中播放 MediaPlayer player = ne ...

  3. PHP 冒泡原理

    header('Content-Type: text/html; charset=utf-8'); // 简单冒泡算法 $a = array(5,43,3,2,1); function mp($a){ ...

  4. Word Pattern | & II

    Word Pattern | Given a pattern and a string str, find if str follows the same pattern. Examples: pat ...

  5. c++11之bind

    std::bind是个c++推出的新的特性,非常有用,让你写起来率试不爽. #include <iostream> using namespace std; #include <fu ...

  6. iOS 中的Push Notifications简单实现(APNS)

    Android中的通知只有一种,就是Local Notifications,而iOS中除了Local Notifications外,还有一种Push Notifications.ios的这2种noti ...

  7. glGetFloatv (GL_MODELVIEW_MATRIX, mat)

    这个函数的作用是取出GL_MODELVIEW_MATRIX,然后存储在mat这个矩阵中,用于逆变换等.

  8. rdesktop remember

    整个地球都知道rdesktop,有了它,我们可以从Solaris或者Linux使用Windows,当然Windows要开启Windows Terminal Service.虽然也有基于GTK+的tsc ...

  9. register

    register:这个关键字请求编译器尽可能的将变量存在CPU内部寄存器中,而不是通过内存寻址访问,以提高效率.注意是尽可能,不是绝对.你想想,一个CPU 的寄存器也就那么几个或几十个,你要是定义了很 ...

  10. 在qq中可以使用添加标签功能

    而在sina中不可以,现在就保持一致吧!那么每天使用的日志主要是记录工作项目上的问题还有生活的感受