DFS Codeforces Round #299 (Div. 2) B. Tavas and SaDDas

时间:2025-02-09 18:03:39

题目传送门

 /*
DFS:按照长度来DFS,最后排序
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <vector>
using namespace std; const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
int b[] = {, };
int a[MAXN];
int tot; void DFS(int now, int l, int len)
{
if (l == len) {a[++tot] = now; return ;}
for (int i=; i<; ++i)
{
int tmp = now * + b[i];
DFS (tmp, l + , len);
}
} void solve(void)
{
tot = ;
for (int i=; i<=; ++i)
{
DFS (, , i);
}
sort (a+, a++tot);
//for (int i=1; i<=tot; ++i) printf ("%d ", a[i]);
} int main(void) //Codeforces Round #299 (Div. 2) B. Tavas and SaDDas
{
solve ();
int n;
while (scanf ("%d", &n) == )
{
printf ("%d\n", lower_bound (a+, a++tot, n) - a);
} return ;
}