【Undoubtedly Lucky Numbers】【CodeForces - 244B】(dfs+暴力打表)

版权声明:本人原创,未经许可,不得转载 https://blog.csdn.net/qq_42505741/article/details/83818793

题目:
 

Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.

Let's call a positive integer a undoubtedly lucky, if there are such digits x and y(0 ≤ x, y ≤ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.

Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.

Input

The first line contains a single integer n (1 ≤ n ≤ 109) — Polycarpus's number.

Output

Print a single integer that says, how many positive integers that do not exceed nare undoubtedly lucky.

Examples

Input

10

Output

10

Input

123

Output

113

Note

In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.

In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.

解题报告:题目很简单就是给你一个数字n,问小于等于n有多少个幸运数字,幸运数字的定义就是其只由1或者2位数字循环组成的,因为之前做过类似的题目,就是dfs把每位的情况都实现出来,虽然n的数据范围达到了1e9,然而实际数字数目远远小于这个,就不用担心会爆内存了。

ac代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
typedef long long ll;

const int  maxn=1e5+1000;	
set<ll> a;
int n,x,y;
void dfs(ll num,int pos)	
{
	if(num>n||pos>10)
		return;
	a.insert(num);
	dfs(num*10+x,pos+1);
	dfs(num*10+y,pos+1);
}
int main()
{
	scanf("%d",&n);
		for(x=0;x<10;x++)
			for(y=x+1;y<10;y++)
				dfs(0,0);
	printf("%d\n",a.size()-1);
}       
//这里偷懒使用了x y为全局变量,使得dfs简化了数据。

猜你喜欢

转载自blog.csdn.net/qq_42505741/article/details/83818793