hdu 2089 不要62 数位dp
2017-02-17 11:22
375 查看
题目大意
求L-R区间内不含有4和62的数字有多少个数位dp一波
注意
最高位也要判断是否不满足直接returnsolution
#include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cmath> #include <algorithm> using namespace std; const int M=1000007; const int N=8; inline int rd(){ int x=0;bool f=1;char c=getchar(); for(;!isdigit(c);c=getchar()) if(c=='-') f=0; for(;isdigit(c);c=getchar()) x=x*10+c-48; return f?x:-x; } int n,m; int bit ,cnt; int f[8][10]; void getbit(int d){ cnt=0; for(;d>0;d/=10) bit[++cnt]=d%10; } int dp(int d){ getbit(d); int i,j,lst,res=0; for(i=1;i<cnt;i++) for(j=1;j<=9;j++) res+=f[i][j]; for(i=1;i<bit[cnt];i++) res+=f[cnt][i]; lst=bit[cnt]; if(lst==4) return res;//**** for(i=cnt-1;i>0;i--){ for(j=0;j<bit[i];j++) res+=f[i][j]; if(bit[i]>2&&lst==6) res-=f[i][2]; if(bit[i]==2&&lst==6) break; if(bit[i]==4) break; lst=bit[i]; } return res; } void init(){ f[0][0]=1; int i,j,k; for(i=1;i<N;i++) for(j=0;j<=9;j++) if(j!=4){ for(k=0;k<=9;k++) if(!(j==6&&k==2)){ f[i][j]+=f[i-1][k]; } } } int main(){ init(); while(1){ n=rd(),m=rd(); if(n==0&&m==0) return 0; m++; printf("%d\n",dp(m)-dp(n)); } return 0; }
相关文章推荐
- HDU 2089 不要62 还是基础数位dp
- hdu 2089(不要62)数位DP
- HDU-2089 不要62 数位DP 模板题
- HDU - 2089 不要62 (暴力或数位DP)
- hdu 2089 不要62--数位dp入门
- hdu 2089 不要62 数位DP
- HDU 2089:不要62(数位DP)
- HDU 2089 不要62(数位dp)
- HDU 2089 不要62(数位DP)
- [HDU 2089]不要62[数位DP]
- hdu 2089 不要62(数位dp)
- hdu 2089 不要62 hdu 3555 Bomb (数位DP)
- HDU 2089 不要62 数位dp入门
- hdu 2089 不要62--数位dp入门
- HDU 2089 不要62(数位DP)
- hdu 2089 不要62(数位DP)
- hdu 2089 不要62 --- 数位dp
- HDU 2089——不要62(数位DP)
- hdu 2089 不要62 数位dp
- HDU 2089 不要62(数位DP入门)