/** 题目:poj3208 Apocalypse Someday 链接:http://poj.org/problem?id=3208 题意:求第K(K <= 5*107)个有连续3个6的数. 思路:数位dp+二分. dp[i][j]表示长度为i,前缀状态为j时含有的个数. j=0表示含有前导0: j=1表示前缀连续1个6 j=2表示前缀连续2个6 j=3表示前缀连续3个6 j=4表示前缀不是6: */ //#include<bits/stdc++.h> #include<cstr…
数位中出现至少3个连续的'6'的数字(称魔鬼数),询问满足要求的排名k的数. 经典题型.采用试填法. 递推做法:预处理出$i$位数字中满足要求的数(下记为'魔鬼数').对每一位都从0到9试一遍,然而卡在了试填时试到6这个数时该怎么办,不太会做.然后才知道可以记录填到目前的上一位已有多少个连续的6,这样可以配合当前的计算出来. 所以就有这个$f[i][0]=9*(f[i-1][0]+f[i-1][1]+f[i-1][2]),f[i][1]=f[i-1][0],f[i][2]=f[i-1][1],f…
Apocalypse Someday Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 1807   Accepted: 873 Description The number 666 is considered to be the occult “number of the beast” and is a well used number in all major apocalypse themed blockbuster…
数位DP加二分 //数位dp,dfs记忆化搜索 #include<iostream> #include<cstdio> #include<cstring> using namespace std; typedef long long LL; #define N 20 LL dp[N][3];//dp[i][j]表示长度为i,前面有j个6时不含666的数的个数 int num[N]; //c6表示前面6的个数 LL dfs(int len, int c6, bool is…
只要某数字的十进制表示中有三个6相邻,则该数字为魔鬼数,求第X小的魔鬼数\(X\le 5e7\) 这一类题目可以先用DP进行预处理,再基于拼凑思想,用"试填法"求出最终的答案 \(F[i,3]\)表示由 \(i\) 位数字构成的魔鬼数有多少个,\(F[i,j](0\le j\le 2)\) 表示由 \(i\) 位数字构成的,开头已经有连续 \(j\) 个6的非魔鬼数有多少个.(允许前导0的存在,想一想为什么) 转移方程 \(F[i,0] = 9*(F[i-1,0] + F[i-1,1]…
题意 Language:Default Apocalypse Someday Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 2499 Accepted: 1288 Description The number 666 is considered to be the occult "number of the beast" and is a well used number in all major apocaly…
积累点: 1: (l&r)+((l^r)>>) == (l+r)/2 2: 注意判断现在是否有限制.当枚举下一个量时,是(isQuery && j==end),不要搞错. 传送门:http://acm.upc.edu.cn/problem.php?id=2223 题意: 能被7整除或者含7的数称为A-Number,所有A-Number从小到大写好,下标编号(从1开始),去掉那些下标为A-Number的数,剩下的数称为B-Number.求第N个B-Number是多少. 思…
题目链接: http://hihocoder.com/problemset/problem/1301?sid=804672 题解: 二分答案,每次判断用数位dp做. #include<iostream> #include<cstring> #include<cstdio> using namespace std; typedef long long LL; const LL INFLL = 0x3f3f3f3f3f3f3f3fLL; //dp[x][0]表示高位还没有出…
题意:求1-n的n个数字中1出现的个数. 解法:数位dp,dp[pre][now][equa] 记录着第pre位为now,equa表示前边是否有降数字(即后边可不能够任意取,true为没降,true为已降):常规的记忆化搜索 代码: /****************************************************** * author:xiefubao *******************************************************/ #p…
All submissions for this problem are available. Chef likes numbers and number theory, we all know that. There are N digit strings that he particularly likes. He likes them so much that he defines some numbers to be beautiful numbers based on these di…