P4124 [CQOI2016]手機號碼

來源:互聯網
上載者:User

標籤:freopen   list   eof   說明   badge   size   +=   條件   etc   

連結:https://www.luogu.org/problemnew/show/P4124

題目描述

人們選擇手機號碼時都希望號碼好記、吉利。比如號碼中含有幾位相鄰的相同數字、不含諧音不吉利的數字等。手機電訊廠商在發行新號碼時也會考慮這些因素,從號段中選取含有某些特徵的號碼單獨出售。為了便於前期規劃,電訊廠商希望開發一個工具來自動統計號段中滿足特徵的號碼數量。

工具需要檢測的號碼特徵有兩個:號碼中要出現至少 33 個相鄰的相同數字;號碼中不能同時出現 88 和 44 。號碼必須同時包含兩個特徵才滿足條件。滿足條件的號碼例如:13000988721、23333333333、14444101000。而不滿足條件的號碼例如:1015400080、10010012022。

手機號碼一定是 11 位元,前不含前置的 00 。工具接收兩個數 LL 和 RR ,自動統計出 [L,R][L,R] 區間內所有滿足條件的號碼數量。 LL 和 RR 也是 1111 位的手機號碼。

輸入輸出格式

輸入格式:

 

輸入檔案內容只有一行,為空白格分隔的 22 個正整數 L,RL,R 。

 

輸出格式:

 

輸出檔案內容只有一行,為 11 個整數,表示滿足條件的手機號數量。

 

輸入輸出範例輸入範例#1: 複製
12121284000 12121285550
輸出範例#1: 複製
5
說明

範例解釋:滿足條件的號碼: 12121285000、 12121285111、 12121285222、 12121285333、 12121285550。

資料範圍: 10^10≤L≤R<10^11 。

題解:數位dp, 還是挺容易yy出來的,但要去掉前置0的情況,<10^10是不合法的

// luogu-judger-enable-o2#include<bits/stdc++.h>using namespace std;#define ll long long#define rt registerconst int M = 2530;ll dp[20][10][2][2][2][2];int digit[20], cnt, tot, bg[M];ll dfs(int dep, bool f, bool two, bool ok, int t, bool a4, bool a8){    if(!dep) return (( !(a4 & a8) ) & ok);    if(!f && dp[dep][t][two][ok][a4][a8] != -1) return dp[dep][t][two][ok][a4][a8];    rt int i = f ? digit[dep] : 9;    ll tmp = 0;    for(; i >= 0; i--){        if(dep==tot&&i==0) continue;        bool ntwo, nok = ok;        if(two && (t == i)) ntwo = 0, nok = 1;        else if(i == t) ntwo = 1;        else ntwo = 0;        tmp += dfs(dep - 1, f & (i == digit[dep]), ntwo, nok, i, a4 | (i == 4), a8 | (i == 8));    }    if(!f)dp[dep][t][two][ok][a4][a8] = tmp;    return tmp;}ll get(ll a){    memset(dp, -1, sizeof(dp));        tot = 0;        while(a){        digit[++tot] = a%10;        a /= 10;    }    if(tot<11) return 0;    ll ans = dfs(tot, 1, 0, 0, 0, 0, 0);    return ans;}ll read(){    ll x = 0; ll f = 1; char c = getchar();    while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();}    while(c<=‘9‘&&c>=‘0‘){x=x*10+c-‘0‘;c=getchar();}    return x*f;}int main(){    ///freopen("1.in","r",stdin);    //freopen("my.out","w",stdout);    int T;    memset(dp, -1, sizeof(dp));    ll L = read(), R = read();    ll ans2 = get(L - 1);    ll ans1 = get(R);    //cout<<ans1<<" "<<ans2;    cout<<ans1-ans2<<endl;}//10000000000 10000012345
View Code

 

P4124 [CQOI2016]手機號碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.