hdu 3555 Bomb 题意: 在1~N(1<=N<=2^63-1)范围内找出含有 ‘49’的数的个数: 与hdu 2089 不要62的区别:2089是找不不含 '4'和 '62'的区间范围内的数,此题是含有:正好相反,对于 "不要62"只是用第二位表示首位数字,这一题呢? 看转化:易知一定要要知道首位是9的个数,才能在前面加4得到 '49',但是什么状态能从不含 '49'转移到含 '49'?直接在不含'49'前加9,那么就出现了三个状态之间的递推转化,从而推出了第二维…
[HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #include<cstring> using namespace std; int a[20]; __int64 dp[20][11]; void digit_dp() { memset(dp, 0LL, sizeof(dp)); dp[0][0]=1; for(int i=1; i<20; ++i)…
Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 15102    Accepted Submission(s): 5452 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) 问题描述 The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bo…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the curre…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题意:上一题是不要62 这个是"不要49" 代码: #include <stdio.h> #include <ctime> #include <math.h> #include <limits.h> #include <complex> #include <string> #include <functio…
Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 11804    Accepted Submission(s): 4212 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorist…
数位dp: 数位dp是一种计数用的dp,一般就是要统计一个区间[li,ri]内满足一些条件数的个数.所谓数位dp,字面意思就是在数位上进行dp.数位的含义:一个数有个位.十位.百位.千位......数的每一位就是数位.一般都通过dfs来递归找寻. 数位dp与dfs爆搜之间的区别就是前者会记录状态以便优化下一次寻找的时间(也就是记忆化操作) 数位dp操作: 例如给你一个区间[12,12345],你需要找到这个区间内满足条件的数的个数.这个时候我们一般都是先找[0,12345]这个区间满足条件数的个…
给出n,问所有[0,n]区间内的数中,不含有49的数的个数 数位dp,记忆化搜索 dfs(int pos,bool pre,bool flag,bool e) pos:当前要枚举的位置 pre:当前要枚举的位置的前面是否为4 flag:枚举当前时,这个数的49时候被算过了 e:当前位置是否可以随便取值 dp[pos][pre][flag] #include<cstdio> #include<cstring> #include<algorithm> #include<…
转载请注明出处:http://blog.csdn.net/a1dark 分析:初学数位DP完全搞不懂.很多时候都是自己花大量时间去找规律.记得上次网络赛有道数位DP.硬是找规律给A了.那时候完全不知数位DP为何物.不过还是有很多时候要用数位DP.比如当一个数字超过了数组承受的极限.不能再打表AC.先看这道题.首先划分状态.然后初始化.最后从高位向低位状态转移.代码含详解 //dp[len][0]表示长度为len不含49的数量 //dp[len][1]表示长度为len不含44但以9开头的数字的数量…
题意 求区间[1,n]内含有相邻49的数. 思路 比较简单的按位DP思路.这是第一次学习记忆化搜索式的数位DP,确实比递推形式的更好理解呐,而且也更通用~可以一般化: [数位DP模板总结] int dfs(int pos, int pre, int flag, bool limit) { if (pos == -1) return flag==target_flag; if (!limit && ~dp[pos][pre][flag]) return dp[pos][pre][flag];…
题目链接: Hdu 2089 不要62 题目描述: 给一个区间 [L, R] ,问区间内不含有4和62的数字有多少个? 解题思路: 以前也做过这个题目,但是空间复杂度是n.如果数据范围太大就GG了.今天看了一下数位DP,的确有时间和空间上的优越性. 用数位dp做这个题目的时候,首先要预处理出dp[x][y],代表以y开头的x位数中不含有62和4的数有多少个,在满足条件的情况下状态转移为:dp[x][y] += dp[x-1][k].又因为对于一个数字x,如果和它位数相同的数字y小于x,那么只需要…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题目大意:从0开始到给定的数字N所有的数字中遇到“49”的数字的个数. Sample Input 3 1 50 500   Sample Output 0 1 15 Hint From 1 to 500, the numbers that include the sub-sequence "49" are "49","149","24…
Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 7926    Accepted Submission(s): 2780 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists…
链接: https://vjudge.net/problem/HDU-3555 题意: The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence includes…
Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 24148    Accepted Submission(s): 9092 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorist…
题意: 给一个数字n,求从1~n中有多少个数是含有49的,比如49,149,1490等都是含49的. 思路: 2^64也顶多是十进制的20多位,那么按十进制位来分析更简单.如果能计算k位十进制数中分别有多少个含49的,那么计算就简单了. 首先要求关于十进制位的一些信息,比如:i位的十进制数包含49有多少个,不包含49的多少个(除掉最高位是9的数量),不包含49但是最高位是9的有多少个(因为可能和更高一位组合成49).注意精度,注意爆longlong. #include <bits/stdc++.…
RT. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ],ret=,dp[][][]; void get_bit(long long x) { ret=; ;x/=;} } long long dfs(long long pos,long long pre,bool flag1,long long flag2) {…
hdu 3652 B-number Problem Description A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string “13” and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your…
HDU 2089 不要62 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2089 Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众.不吉利的数字为所有含有4或62的号码.例如:62315 73418 88914都属于不吉利号码.但是,6115…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 简单的数位DP入门题目 思路和hdu2089基本一样 直接贴代码了,代码里有详细的注释 代码: #include<iostream> #include<cstdlib> #include<cstdio> #include<cstring> using namespace std; ][]; void init() { dp[][]=;dp[][]=;dp[…
开学之后完全没时间写博客.... HDU 2089 不要62(vjudge) 数位DP 思路: 题目给出区间[n,m] ,找出不含4或62的数的个数 用一个简单的差分:先求0~m+1的个数,再减去0~n的个数. 但问题依旧不简单,再次简化为求0~i位数中不含4或62的数的个数. i= //0~9中 i= //0~99中 i= //0~999中 ...... dp[i][] //0~i位数中的吉利数 dp[i][] //0~i位数中以2打头的吉利数 dp[i][] //0~i位数中的非吉利数(含4…
 数位DP总结 By Wine93 2013.7 1.学习链接 [数位DP] Step by Step   http://blog.csdn.net/dslovemz/article/details/8540340 [总结] 数位统计模板 http://www.cnblogs.com/jffifa/archive/2012/08/17/2644847.html 2.各人总结领悟 数位DP关键在于状态的设计,设计状态时要考虑当前状态(如dp[pos][s1][s2]),一旦当前状态确定后,pos后…
        ID Origin Title   62 / 175 Problem A CodeForces 55D Beautiful numbers   30 / 84 Problem B HDU 4352 XHXJ's LIS   108 / 195 Problem C HDU 2089 不要62   89 / 222 Problem D HDU 3555 Bomb   59 / 107 Problem E POJ 3252 Round Numbers   47 / 75 Problem…
第一题:Amount of degrees (ural 1057) 题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1057 题意:[x,y]范围内的数,可以拆分成k个b进制的不同幂的和 的数字有多少. 我们可以将x转换成二进制来讨论.二进制转化时,找到第一个非0非1的数,将其及其后面的数都变为1. 那么问题就变成了求[0,x]范围内,二进制表示中含有k个1的数字有多少个. 求[x,y]区间相减.我们可以给数建立0,1的表示树. 在求高度为i的…
算法笔记 这个博客写的不错:http://blog.csdn.net/wust_zzwh/article/details/52100392 数位dp的精髓是不同情况下sta变量的设置. 模板: ]; ll dp[][state];//不同题目状态不同 ll dfs(int pos,/*state变量*/,bool lead/*前导零*/,bool limit/*数位上界变量*/)//不是每个题都要判断前导零 { //递归边界,既然是按位枚举,最低位是0,那么pos==-1说明这个数我枚举完了 )…
以前一直不知道该咋搞这个比较好. 感觉推起来那个数字好麻烦.后来有一种比较好的写法就是直接的DFS写法.相应的ismax表示当前位是否有限制. 数位DP也是有一种类似模版的东西,不过需要好好理解.与其他模版不同. 主要还是状态的定义 模版就不整理了.直接上题. 另外这里有一道题是数位DP+自动机的放到自动机里做 HDU 2089 不要62 基本的数位DP可以用来理解DFS写法 #include <map> #include <set> #include <list> #…
BZOJ  1026: [SCOI2009]windy数: 题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1026           dp[11][11][2]:dep,pre,f 要求的性质就是相邻数字差至少是2.          递归函数的状态设计如下dep,pre,f,分别表示已经枚举到第dep位,他的前一位(更高的位)是pre,f表示大小关系是否已经确定. #include<bits/stdc++.h> using na…
前言 复习笔记第五篇.(由于某些原因(见下),放到了第六篇后面更新)CSP-S RP++. luogu 的难度评级完全不对,所以换了顺序,换了别的题目.有点乱,见谅.要骂就骂洛谷吧,原因在T2处 由于半路换题,中间耽搁了一天等原因,所以此文的阅读体验不一定和前5篇相当,见谅. 注:此文大部分建议结合代码阅读,便于解释 0--HDU 3555 Bomb link 题意 求 \(1\sim N\) 中包含子串 49 的个数.\(N\leq 2^{63}-1.\) 思路 设 \(f[i][0]\) 表…
传送门 A.CodeForces - 55D Beautiful numbers 题意 一个正整数是 漂亮数 ,当且仅当它能够被自身的各非零数字整除.我们不必与之争辩,只需计算给定范围中有多少个漂亮数. 思路 因为问你的是一段区间内有多少数能整除他的所有非零数位 1-9,1,一定能被任何正整数整除,1-9的最小公倍数为2520 而1-2520中真正是1-9中的最小公倍数的只有48个 dp i j k:因为dp25,2520,[2520]开不下,所以我们要进行适当离散化 index[]数组标记1-…