TOJ 3504 Repeatless Numbers / 深搜
来源:互联网 发布:manifest.json 编辑:程序博客网 时间:2024/05/18 01:51
Repeatless Numbe
时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte
描述
Arepeatless 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 thenth repeatless number.
输入
The input test file will contain multiple test cases, each consisting of a single line containing the integern, where 1 ≤n ≤ 1000000. The end-of-file is marked by a test case withn = 0 and should not be processed.
输出
For each input case, the program should print the nth repeatless number on a single line.
样例输入
25100000
样例输出
2726057
#include <stdio.h>int a[1000010];int t = 0;int map[10];void dfs(int sum,int k,int flag)//flag=0是表示0可以无限用 flag=1表示0只能用一次 00000001 {if(k == 8){a[t++] = sum;return;}if(t > 1000000)return;int i;for(i = 0; i < 10; i++){if(i == 0){if(!flag)//0000000就是这种情况 前面的0可以随便用 {dfs(0,k+1,0);}else//flag=1 你们说明 比如00000010最后这个0 只能用1次 {if(!map[i]){map[i]=1;dfs(sum*10+i,k+1,1);map[i]=0;}}}else{if(!map[i]){map[i]=1;dfs(sum*10+i,k+1,1);map[i]=0;}}}}int main(){dfs(0,0,0);int n;while(scanf("%d",&n),n){printf("%d\n",a[n]);}return 0;}
- TOJ 3504 Repeatless Numbers / 深搜
- TOJ:2971. Rotating Numbers
- TOJ 1477. Binary Numbers
- TOJ 1203.Factoring Large Numbers
- TOJ 2353.Reduced ID Numbers
- TOJ 2931 Raising Modulo Numbers 快速幂
- TOJ 1134 Lotto 深搜
- TOJ 4399 Deal with numbers / 线段树成段更新
- TOJ 3293.A Sequence of Numbers(快速幂取余)
- TOJ 2424 POJ 2325 ZOJ 1923 Persistent Numbers /贪心 + 大数除法
- TOJ 2921 古韵之鹊桥相会 / 深搜
- TOJ 4267 An Easy Puz / 深搜
- TOJ 4367 ZOJ 3631 Watashi's BG / 背包 深搜
- TOJ 2976
- toj 3140
- toj 1153
- TOJ 1772
- TOJ 3250
- oracle中对时间的操作以及to_char和to_date用法总结
- WebService:设置服务器提供SOAP1.2的服务
- javascript脚本何时被执行
- sqoop的安装、配置及使用简介
- 把权限管理做到最好,把业务做到最好
- TOJ 3504 Repeatless Numbers / 深搜
- linux下nginx服务器重启命令关闭
- windows默认共享的打开和关闭
- 冒泡排序,插入排序,快速排序 简单总结
- 与Android的系统打交道
- Android异步处理一:使用Thread+Handler实现非UI线程更新UI界面
- QT 5.1.1 for Android 开发环境搭建与配置【Windows 7】
- ubuntu下到s3c6410开发板到环境搭建
- 烧写开发板