AtCoder--755——dfs

简介: 题目描述You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally “Seven-Five-Three numbers”) are there?Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:

题目描述


You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally “Seven-Five-Three numbers”) are there?


Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:


When the number is written in base ten, each of the digits 7, 5 and 3 appears at least once, and the other digits never appear.

Constraints

1≤N<109

N is an integer.


输入


Input is given from Standard Input in the following format:
N


输出


Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).


样例输入


575


样例输出


4


提示


There are four Shichi-Go-San numbers not greater than 575: 357,375,537 and 573.


#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define wuyt main
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
//#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
#define read read()
const ll inf = 1e15;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
#define start int wuyt()
#define end return 0
int n,ans;
void dfs(int sum, unsigned char ss){
    if(sum>n)
        return;
    if(ss==07)
        ans++;
    if(sum<99999999){
        dfs(sum*10+3,ss|1);
        dfs(sum*10+5,ss|2);
        dfs(sum*10+7,ss|4);
    }
}
start{
    /**
    ll x=read;
    if(x==7||x==5||x==3)
        printf("YES\n");
    else
        printf("NO\n");
    string s;
    cin>>s;
    int len=s.size();
    int ans=999;
    for(int i=0;i<=len-3;++i)
    {
        int num=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
        ans=min(abs(num-753),ans);
    }
    cout<<ans;**/
    n=read;
    dfs(0,0);
    cout<<ans;
    end;
}


目录
相关文章
|
9月前
|
算法
1091 zoj Knight Moves的BFS算法和DFS
1091 zoj Knight Moves的BFS算法和DFS
37 0
CF711D-Directed Roads(组合数学 dfs找环)
CF711D-Directed Roads(组合数学 dfs找环)
64 0
CF711D-Directed Roads(组合数学 dfs找环)
AtCoder Beginner Contest 226 E - Just one(dfs求连通块 组合数学)
AtCoder Beginner Contest 226 E - Just one(dfs求连通块 组合数学)
82 0
CodeForces 377A-Maze(DFS找连通块)
CodeForces 377A-Maze(DFS找连通块)
CodeForces 377A-Maze(DFS找连通块)
洛谷P6207-[USACO06OCT] Cows on Skates G(DFS记录路径)
洛谷P6207-[USACO06OCT] Cows on Skates G(DFS记录路径)
POJ-2488,A Knight's Journey(DFS)
POJ-2488,A Knight's Journey(DFS)
|
机器学习/深度学习
HDOJ 2212 DFS
HDOJ 2212 DFS
95 0