hdu_2089_不要62(数位DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2089
题意:中文,不解释
题解:dp[i][j]表示当前第i位的前一个数为j,然后记忆化dfs,注意的是给的是一个区间,容斥完后要处理大的那个数
#include<cstdio>
#include<cstring>
#define F(i,a,b) for(int i=a;i<=b;i++) int dp[][],n,m,dig[],len,ans1,tmp,fg,pre; int dfs(int pos,int pre,bool inf){
if(!pos)return !inf;
if(!inf&&dp[pos][pre]!=-)return dp[pos][pre];
int end=(inf?dig[pos]:),ans=;
F(i,,end)if(!(pre==&&i==||i==))ans+=dfs(pos-,i,inf&&(i==end));
if(!inf)dp[pos][pre]=ans;
return ans;
} int main(){
memset(dp,-,sizeof(dp));
while(~scanf("%d%d",&n,&m),n+m){
for(len=;n;)dig[++len]=n%,n/=;
ans1=dfs(len,,);
for(tmp=m,fg=,pre=-;tmp;pre=tmp%,tmp/=)
if(tmp%==)fg=;else if(tmp%==&&pre==)fg=;
for(len=;m;)dig[++len]=m%,m/=;
printf("%d\n",dfs(len,,)+fg-ans1);
}
return ;
}
hdu_2089_不要62(数位DP)的更多相关文章
- HDU2089 不要62[数位DP]
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 【Hdu2089】不要62(数位DP)
Description 题目大意:给定区间[n,m],求在n到m中没有"62"或"4"的数的个数. 如62315包含62,88914包含4,这两个数都是不合法的 ...
- HDU 2089 - 不要62 - [数位DP][入门题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...
- HDU 2089 不要62(数位DP·记忆化搜索)
题意 中文 最基础的数位DP 这题好像也能够直接暴力来做 令dp[i][j]表示以 j 开头的 i 位数有多少个满足条件 那么非常easy有状态转移方程 dp[i][j] = sum{ dp[ ...
- [hdu 2089] 不要62 数位dp|dfs 入门
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 题意:求[n, m]区间内不含4和62的数字个数. 这题有两种思路,直接数位dp和dfs 数位d ...
- HDU2089 不要62 —— 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 不要62 Time Limit: 1000/1000 MS (Java/Others) M ...
- Hdu 2089 不要62 (数位dp入门题目)
题目链接: Hdu 2089 不要62 题目描述: 给一个区间 [L, R] ,问区间内不含有4和62的数字有多少个? 解题思路: 以前也做过这个题目,但是空间复杂度是n.如果数据范围太大就GG了.今 ...
- hdu2089不要62(数位dp)
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 2089 不要62 数位DP模板题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 参考博客:https://www.cnblogs.com/HDUjackyan/p/914215 ...
随机推荐
- Documention
Object.bool Does the object exist? Object.name Components share the same name with the game object a ...
- awstats 日志分析
/tmp/awstats/awstats.ezrydel.com.conf LogFile="/usr/local/apache/domlogs/ezrydel.com" php版 ...
- js-常用数组方法总结
[前面的话]说数组“万能”,可能夸张了一点,但是就个人观点,数组的运用是非常广泛的,这里的广泛当然也包含了在其他语言中的运用.举例说明,在javascript当中,由于字符串的不可变性,在进行字符串拼 ...
- Eclipse Kepler maven工程配置JDK1.8
首先需要下载插件:"Help" --> "Market Place" --> Search for java 8 kepler. install J ...
- php基础(六)Include
本文内容来自http://www.w3school.com.cn/php/php_file.asp 服务器端包含 (SSI) 用于创建可在多个页面重复使用的函数.页眉.页脚或元素. include ( ...
- POJ 1042 Gone Fishing#贪心
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cstring> using namespace std ...
- LeetCode OJ combine 3
public class Solution { public List<List<Integer>> combinationSum3(int k, int n) { retur ...
- html的表单表格...
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- CreateCompatibleBitmap 需要注意的问题
不要使用CreateCompatibleDC得到的内存DC作为其参数,应使用真实DC,否则图片不能显示
- chapter8_4 错误处理
在Lua中,对于大多数程序都不用作任何错误处理,应用程序本身会负责这类问题. 所有的Lua活动都是由应用程序的一次调用开始的,这类调用要求Lua执行一个程序块. 执行过程中发生了错误,此调用会返回一个 ...