研究生算法 2-1 YY and Lucky Number

研究生算法 2-1 YY and Lucky Number

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll n, ans;

void dfs(int A, int B, ll now) {
	if (now > n) {
		return;
	}
	ans++;
	if (A != B) {
		dfs(A, B, now * 10 + A);
		dfs(A, B, now * 10 + B);
	}
	else {
		for (int i = 0; i <= 9; i++) {
			dfs(B, i, now * 10 + i);
		}
	}
}

int main () {
	
	cin >> n;
	if (n <= 9) {
		cout << n << endl;
		exit(0);
	}
	
	ans = 9;
	for (int i = 1; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			dfs(i, j, i * 10 + j);
		}
	}

	cout << ans << endl;
}

上一篇:LeetCode 417 太平洋大西洋水流问题


下一篇:洋流的仿真matlab源码