CF——#150div2B

来源:互联网 发布:黑马程序员有用吗 编辑:程序博客网 时间:2024/04/28 23:55

题目地址:http://codeforces.com/contest/244/problem/B

解析:深搜下就可以了。

#include <iostream>#include <cstring>typedef  long long ll;using namespace std;#define N 1005ll 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;}


原创粉丝点击