标签:
1 /*
2 DFS:按照长度来DFS,最后排序
3 */
4 #include <cstdio>
5 #include <algorithm>
6 #include <cstring>
7 #include <iostream>
8 #include <cmath>
9 #include <vector>
10 using namespace std;
11
12 const int MAXN = 1e3 + 10;
13 const int INF = 0x3f3f3f3f;
14 int b[2] = {4, 7};
15 int a[MAXN];
16 int tot;
17
18 void DFS(int now, int l, int len)
19 {
20 if (l == len) {a[++tot] = now; return ;}
21 for (int i=0; i<2; ++i)
22 {
23 int tmp = now * 10 + b[i];
24 DFS (tmp, l + 1, len);
25 }
26 }
27
28 void solve(void)
29 {
30 tot = 0;
31 for (int i=1; i<=9; ++i)
32 {
33 DFS (0, 0, i);
34 }
35 sort (a+1, a+1+tot);
36 //for (int i=1; i<=tot; ++i) printf ("%d ", a[i]);
37 }
38
39 int main(void) //Codeforces Round #299 (Div. 2) C. Tavas and Karafs
40 {
41 solve ();
42 int n;
43 while (scanf ("%d", &n) == 1)
44 {
45 printf ("%d\n", lower_bound (a+1, a+1+tot, n) - a);
46 }
47
48 return 0;
49 }
1 /*
2 DFS:按照长度来DFS,最后排序
3 */
4 #include <cstdio>
5 #include <algorithm>
6 #include <cstring>
7 #include <iostream>
8 #include <cmath>
9 #include <vector>
10 using namespace std;
11
12 const int MAXN = 1e3 + 10;
13 const int INF = 0x3f3f3f3f;
14 int b[2] = {4, 7};
15 int a[MAXN];
16 int tot;
17
18 void DFS(int now, int l, int len)
19 {
20 if (l == len) {a[++tot] = now; return ;}
21 for (int i=0; i<2; ++i)
22 {
23 int tmp = now * 10 + b[i];
24 DFS (tmp, l + 1, len);
25 }
26 }
27
28 void solve(void)
29 {
30 tot = 0;
31 for (int i=1; i<=9; ++i)
32 {
33 DFS (0, 0, i);
34 }
35 sort (a+1, a+1+tot);
36 //for (int i=1; i<=tot; ++i) printf ("%d ", a[i]);
37 }
38
39 int main(void) //Codeforces Round #299 (Div. 2) C. Tavas and Karafs
40 {
41 solve ();
42 int n;
43 while (scanf ("%d", &n) == 1)
44 {
45 printf ("%d\n", lower_bound (a+1, a+1+tot, n) - a);
46 }
47
48 return 0;
49 }
DFS Codeforces Round #299 (Div. 2) C. Tavas and Karafs
标签:
原文地址:http://www.cnblogs.com/Running-Time/p/4547439.html