日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

【题解】P4124 [CQOI2016]手机号码

發布時間:2025/3/21 56 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【题解】P4124 [CQOI2016]手机号码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

\(Desciption:\)

給出區間 \([L,R]\) ,求區間內滿足沒有 \(4\)\(8\) 同事出現并且一定要有三位連續的相同。

并且一定是十一位的電話號碼。

\(Sample\) \(Input:\)

12121284000 12121285550

\(Sample\) \(Output:\)

5

\(Solution:\)

考慮數位dp,一眼就是啊。。。

不然數據范圍不會這么大。。。

那么傳入好多個參數:

位數(\(len\)),是否有 \(4\) (\(if4\)), 是否有 \(8\) (\(if8\)),是否有連續的三個數(\(ifc\)),上一個的上一個是啥子(\(prepre\)),上一個是啥子(\(pre\)),取得上限(\(limit\))。

代碼就非常顯然了,但要注意如果 \(l==1e10\) 那么不能直接算 \(l-1\) 的合法個數,只能減去 \(0\)

個人認為這題除了傳入參數要大膽,其他也沒啥子了。。。

#include<bits/stdc++.h> #define int long long using namespace std; int l,r,cnt; const int N=12; int f[N][2][2][2][N][N],digit[N]; inline int dfs(int len,bool if4,bool if8,bool ifc,int prepre,int pre,bool limit){if(if4 && if8) return 0;if(len==0){if(ifc) return 1;return 0;}if(!limit && f[len][if4][if8][ifc][prepre][pre]!=-1) return f[len][if4][if8][ifc][prepre][pre];int ret=0,up_bound=(limit)?digit[len]:9;for(int i=(len==cnt);i<=up_bound;++i){ret+=dfs(len-1,if4||(i==4),if8||(i==8),ifc||((i==prepre) && (i==pre)),pre,i,limit&&(i==up_bound)); }return f[len][if4][if8][ifc][prepre][pre]=ret; } inline int solve(int x){if(x<(int)1e10) return 0;cnt=0;memset(f,-1,sizeof(f));while(x) digit[++cnt]=x%10,x/=10;return dfs(cnt,false,false,false,-10,-10,true); } signed main(){scanf("%lld%lld",&l,&r);printf("%lld\n",solve(r)-solve(l-1));return 0; }

轉載于:https://www.cnblogs.com/JCNL666/p/10717490.html

總結

以上是生活随笔為你收集整理的【题解】P4124 [CQOI2016]手机号码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。