please could help me with the problem B. Undoubtedly Lucky Numbers using DFS and please excuse my English
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 151 |
please could help me with the problem B. Undoubtedly Lucky Numbers using DFS and please excuse my English
Name |
---|
using namespace std;
const int N = 123;
set st; ll n, m[20], c, sum, cdg, tt;
ll calc(int sz) {
ll ans = 0, res = 1; for (int j = sz; j >= 1; --j) { ans += res * m[j]; res *= 10; }
return ans; }
void f(int cnt, int x, int y) {
if(cnt == 1) { if(y == 0) { m[cnt] = x;
f(cnt + 1, x, y); } else {
m[cnt] = x; f(cnt + 1, x, y);
}
}
}
}
int main () {
cout << st.size() << endl;
return 0;
}
The main idea is to brute force through all possible pairs of digits (i, j), i <= j. Then, for a specific digit-pair, you can run dfs, simply putting either i or j each time, until the number becomes too large. Depth is maximum 10, due to constraints, so theres only 2^10 calls. You can put every found solution into a set to avoid over-counting (counting the same element a few times). The complexity will be something like 2^10 * 50 * a logarithm of a not very large number.