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

题目链接

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

#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内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部