CodeForces 9C - Hexadecimal's Numbers

向上递归判断就行了。
#include <iostream>
using namespace std;
int res=0;
int dfs(int tmp,int tmp1)
{
    if(tmp<=tmp1)
    {
         res++;
         dfs(tmp*10,tmp1);
         dfs(tmp*10+1,tmp1);
    }
    return res;
}
int main()
{
	int n;
	cin>>n;
	int ans=dfs(1,n);
	cout<<ans<<endl;
	return 0;
}

你可能感兴趣的:(DFS,codeforces)