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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

[CQOI2016]手机号码 数位DP

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

[CQOI2016]手機號碼

用來數位DP入門,數位DP把當前是否需要限制取數范圍(是否正在貼著臨界值跑,即下面的limited)和一切需要滿足的條件全部塞進記憶化搜索參數里面就好了,具體情況轉移便好了,答案為\(work(R)-work(L-1)\)

#include <cstdio> #include <cstring> #define DP dp[p][a][b][hav_same][hav8][hav4][limited] #define ll long long using namespace std; ll dp[14][11][11][2][2][2][2]; int num[14]; ll solve(int p, int a, int b, bool hav_same, bool hav8, bool hav4, bool limited){//當前第p位,前2位為a,前1位為b,hav_same:是否有三個連續相等的,hav_8,hav_4:是否存在數字8\4,是否限制取數范圍if(hav4&&hav8) return 0;if(p<=0) return hav_same;if(DP!=-1) return DP;ll ans=0;int maxnum=(limited?num[p]:9);for(int i=0;i<=maxnum;++i)ans+=solve(p-1, b, i, hav_same||(i==a&&i==b), hav8||(i==8), hav4||(i==4), limited&&(i==maxnum));return DP=ans; } ll work(ll x){if(x<1e10) return 0;memset(dp, -1, sizeof(dp));int len;for(len=0;x;x/=10) num[++len]=x%10;ll ans=0;for(int i=num[len];i>=1;--i)ans+=solve(11-1, -1, i, 0, i==8, i==4, i==num[len]);return ans; } int main(){ll l,r;scanf("%lld %lld", &l, &r);printf("%lld\n", work(r)-work(l-1));return 0; }

轉載于:https://www.cnblogs.com/santiego/p/11185422.html

總結

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

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