随笔分类 -  数位DP

DP
摘要:我滴头啊~晕啊晕。这题终于让我把数位DP的本质看清楚了。http://acm.fzu.edu.cn/problem.php?pid=2109题目Problem DescriptionOne integer number x is called "Mountain Number" if:(1) x>0 and x is an integer;(2) Assume x=a[0]a[1]...a[len-2]a[len-1](0≤a[i]≤9, a[0] is positive). Any a[2i+1] is larger or equal to a[2i] and a[ 阅读全文
posted @ 2013-04-17 21:44 小仪在努力~ 阅读(432) 评论(0) 推荐(0)
摘要:数位DP=区间求符合条件的数的个数的算法=数很大,无法直接暴力的算法≈让人苦恼愤怒,依然D不出来的勾魂算法数位DP的两种写法:1、递推结构:init()函数,根据递推数位的公式求得的满足某长度的符合数的个数cal()函数,假设要计算的数字为n,数位长度为len。1到len-1长度累加,len长度的拿出来一个位置一个位置遍历判定再累加。输出cal(right+1)-cal(left),right为区间最右,left为区间最左模板:int f[35][35],digit[35];void Init(){ int i,j; /*递推关系式,请忽略 f[0][0]=1; for... 阅读全文
posted @ 2013-04-11 20:51 小仪在努力~ 阅读(387) 评论(0) 推荐(0)
摘要:/*我实在不敢说这是一道简单题,搞数位DP都搞了差不多2周了,居然还没搞完,好吧,这道题是数位DP里比较简单的题。思路:题意要求在[x,y]中,含有刚好k个b进制不同整数次幂的数有多少个,假如k=2,ai为不同的整数次幂,符合条件的数必须是C=b^a1+b^a2,也就是说,对于C的b进制数所有的位必须为0,或者是1(注意严格要求k个,不允许有重复的degree)*/#include<iostream>#include<cstring>#include<cstdio>using namespace std;#define LL long longint f[3 阅读全文
posted @ 2013-04-03 16:29 小仪在努力~ 阅读(222) 评论(0) 推荐(0)
摘要:#include<iostream>#include<algorithm>using namespace std;#define LL long longLL f[12][10],dp[12],digit[13];//f[i][j]表示第i位为j,且长度为i的windy数的个数//d[i]表示长度为i的windy数的个数LL cal(LL n){ if(n<10) return n-1; int len=0,i,j; LL ans=0; while(n) { digit[++len]=n%10; n/=10; } for(i... 阅读全文
posted @ 2013-03-28 21:21 小仪在努力~ 阅读(187) 评论(0) 推荐(0)
摘要:/*区间求不含有62和4的数量,我的第一道数位DP*/#include<stdio.h>#include<iostream>#include<cstring>using namespace std;int dp[20][3];int cal(int key){ int digit[20],len=0,ans=0; memset(digit,0,sizeof(digit)); int ok=key; while(ok) { digit[++len]=ok%10; ok/=10; } bool flag=false; fo... 阅读全文
posted @ 2013-03-28 16:39 小仪在努力~ 阅读(299) 评论(0) 推荐(0)