ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

【luogu4124】【bzoj4521】 [CQOI2016]手机号码 [数位dp]

2019-06-10 21:00:35  阅读:264  来源: 互联网

标签:10 ch int ll bzoj4521 luogu4124 CQOI2016 isdigit include


P4124 [CQOI2016]手机号码

4521

这道题要注意卡上下界

我错了 写dfs版的更好考虑状态 写纯方程转移那个细节把我想瓜了

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<queue>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<stack>
 7 #include<algorithm>
 8 using namespace std;
 9 #define ll long long
10 #define rg register
11 const int N=2000000000+5,inf=0x3f3f3f3f,P=19650827;
12 ll a,b;
13 ll base[20],f[15][10][10][2][2][2];
14 ll num[20];
15 template <class t>void rd(t &x)
16 {
17     x=0;int w=0;char ch=0;
18     while(!isdigit(ch)) w|=ch=='-',ch=getchar();
19     while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
20     x=w?-x:x;
21 }
22 
23 ll dfs(int pos,int pre,int prr,int h4,int h8,int h,bool dlimi,bool ulimi){
24     if(!pos) return h?1:0;
25     if(!ulimi&&!dlimi&&pre+1&&prr+1&&f[pos][pre][prr][h4][h8][h])
26     return f[pos][pre][prr][h4][h8][h];
27     int up=ulimi?num[pos]:9,dw=dlimi?1:0;
28     ll ans=0;
29     for(int i=dw;i<=up;++i){
30         if(h4&&i==8) continue;
31         if(h8&&i==4) continue;
32         ans+=dfs(pos-1,i,pre,h4||(i==4),h8||(i==8),h||(pre==prr&&prr==i),0,ulimi&&(i==num[pos]));
33     }
34     if(!ulimi&&!dlimi&&pre+1&&prr+1) f[pos][pre][prr][h4][h8][h]=ans;
35     return ans;
36 }
37 ll solve(ll x){
38     int p=0;
39     memset(num,0,sizeof(num));
40     while(x) num[++p]=x%10,x/=10;
41     return p!=11?0:dfs(p,-1,-1,0,0,0,1,1);
42 }
43 
44 int main()
45 {
46     rd(a),rd(b);
47     //memset(f,-1,sizeof(f));
48     printf("%lld",solve(b)-solve(a-1));
49     return 0;
50 }

 

标签:10,ch,int,ll,bzoj4521,luogu4124,CQOI2016,isdigit,include
来源: https://www.cnblogs.com/lxyyyy/p/11000204.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有