题目地址:http://codeforces.com/contest/244/problem/B
解析:深搜下就可以了。
#include <iostream>
#include <cstring>
typedef long long ll;
using namespace std;
#define N 1005
ll ans;
int flag[15];
ll n;
int check(int x)
{
int temp;
int countt=0;
memset(flag,0,sizeof(flag));
while(x)
{
temp=x%10;
if(!flag[temp]) countt++;
flag[temp]++;
if(countt>2) return 0;
x/=10;
}
return 1;
}
void dfs(ll x)
{
int i;
if(x>n) return ;
if(check(x))
{
++ans;
if(x==0) i=1;
else i=0;
for(i;i<10;i++)
dfs(x*10+i);
}
}
int main()
{
while(cin>>n)
{
if(n<=10) cout<<n<<endl;
else
{
ans=0;
dfs(0);
cout<<ans-1<<endl; //减去0.
}
}
return 0;
}