Bomb HDU 3555 dp状态转移】的更多相关文章

题目:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题意: 给出一个正整数N,求出1~N中含有数字“49”的数的个数 思路: 采用数位dp的状态转移方程法解 具体如下: dp[len][state];  dp数组的第一位代表数字的位数,第二位代表状态 状态设定: dp[i][0] : i 位数字中不含数字49的数的个数 dp[i][1] : i 位数字中不含数字49,但高位是9的数的个数 dp[i][0] : i 位数字中含有数字49的数的个数 状…
Bomb HDU - 3555 (数位DP) 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 the sub-sequence "49&…
Bomb HDU - 3555 求1~n中含有49数的个数 #include<bits/stdc++.h> #define LL long long using namespace std; LL T,x,dp[][],shu[]; LL dfs(LL pos,LL x,bool ok,bool limit){ if(!pos) return ok; if(!limit&&dp[pos][x]) return dp[pos][x]; LL cnt=,up=limit?shu[p…
题目链接:https://cn.vjudge.net/contest/278036#problem/A 具体思路:对于给定的数,我们按照位数进行运算,枚举每一位上可能的数,在枚举的时候需要注意几个条件,第一个,当前位上不能是4,第二如果前一位是6的话,当前的这一位不能是2,然后注意这个条件就可以了. AC代码: #include<iostream> #include<stack> #include<iomanip> #include<cmath> #incl…
Code: #include<cstdio> #include<algorithm> #include<cstring> #include<string> #include<iostream> using namespace std; #define ll long long #define N 20 ll f[N][4], str; int arr[N],n; void get_table(){ f[0][0]=1; for(int i=1;i…
题意: 给你N个课程, 每个课程有结束的时间 , 和完成这门课程需要的时间 超过课程结束ed时间,每一天就要花费 1点绩点: 然后要求你安排如何做课程使得花费的绩点最少 (看了博客后才发现状态压缩很⑥) 用二进制表示状态 + 前驱标记 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<stack> using namespace std;…
http://acm.hdu.edu.cn/showproblem.php?pid=4507 求[L,R]中不满足任意条件的数的平方和mod 1e9+7. 条件: 1.整数中某一位是7:2.整数的每一位加起来的和是7的整数倍:3.这个整数是7的整数倍: 首先想到数位DP,我们看下如何维护. 最基本的dp需要两维来维护起始数字和长度,此外对于数位求和mod 7的余数需要一维来维护,对于一个数mod 7的余数需要一维维护. 此外我们处理一下平方和,对于一个x开头,长度为len的xoo型数集,把它分成…
题目链接: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…
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,那么就出现了三个状态之间的递推转化,从而推出了第二维…
转载请注明出处:http://blog.csdn.net/a1dark 分析:初学数位DP完全搞不懂.很多时候都是自己花大量时间去找规律.记得上次网络赛有道数位DP.硬是找规律给A了.那时候完全不知数位DP为何物.不过还是有很多时候要用数位DP.比如当一个数字超过了数组承受的极限.不能再打表AC.先看这道题.首先划分状态.然后初始化.最后从高位向低位状态转移.代码含详解 //dp[len][0]表示长度为len不含49的数量 //dp[len][1]表示长度为len不含44但以9开头的数字的数量…