please could help me with the problem B. Undoubtedly Lucky Numbers using DFS and please excuse my English
# | User | Rating |
---|---|---|
1 | jiangly | 3976 |
2 | tourist | 3815 |
3 | jqdai0815 | 3682 |
4 | ksun48 | 3614 |
5 | orzdevinwang | 3526 |
6 | ecnerwala | 3514 |
7 | Benq | 3482 |
8 | hos.lyric | 3382 |
9 | gamegame | 3374 |
10 | heuristica | 3357 |
# | User | Contrib. |
---|---|---|
1 | cry | 168 |
2 | -is-this-fft- | 165 |
3 | atcoder_official | 161 |
3 | Um_nik | 161 |
5 | djm03178 | 157 |
6 | Dominater069 | 156 |
7 | adamant | 154 |
8 | luogu_official | 152 |
9 | awoo | 151 |
10 | TheScrasse | 147 |
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.