我是靠谱客的博主 粗心人生,这篇文章主要介绍CodeForces - 244B(dfs+剪枝,set),现在分享给大家,希望可以做个参考。

题目链接

题意:求小于n且最多由2个数组成的数的个数

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<bits/stdc++.h> using namespace std; set<long long>a; int n, x, y; void dfs(long long num, long long pos) { if (num > n || pos > 10)return; a.insert(num); dfs(num * 10 + x, pos + 1); dfs(num * 10 + y, pos + 1); } int main() { cin >> n; for (int i = 0; i < 10; i++)for (int j = i + 1; j < 10; j++) { x = i, y = j; dfs(0, 0); } cout << a.size() - 1 << endl; return 0; }

最后

以上就是粗心人生最近收集整理的关于CodeForces - 244B(dfs+剪枝,set)的全部内容,更多相关CodeForces内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部