题意:给你一个n(n<5e7),让你找到第n个包含“666”的数。
思路:妥妥的数位DP,我们可以考虑二分答案,左边界为0,右边界我提前试了一下发现在(1<< 32)之内,我们不断逼近左边界一定可以找到答案,需要注意的是会计算上0,所以要减去1
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define mid ((l + r) >> 1)
const int maxn = 1e5 + 10;
const ll inf = 0x3f3f3f3f;
ll dp[35][35][35];
int a[35];
ll dfs(int pos, int pre1, int pre2, int lead, int limit)
{
if(pos == 0) return 1;
if(!limit && !lead && dp[pos][pre1][pre2] != -1)
return dp[pos][pre1][pre2];
int up = limit ? a[pos] : 9;
ll ret = 0;
for(int i = 0; i <= up; ++i)
{
if(pre1 == 6 && pre2 == 6 && i == 6) continue;
ret += dfs(pos - 1, pre2, i