日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

[HNOI2002] Kathy 函数

發(fā)布時(shí)間:2023/11/27 生活经验 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [HNOI2002] Kathy 函数 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

數(shù)位 DP 套路題,求二進(jìn)制下區(qū)間內(nèi)回文串個(gè)數(shù)。

設(shè) dp[][][] 表示到第幾位時(shí),是否為回文數(shù),去掉前導(dǎo)零后共幾位。之后到邊界時(shí)判斷是否為回文數(shù)計(jì)入貢獻(xiàn)。

一開始不知道答案統(tǒng)計(jì)要高精,于是后來就自閉了。

#include <cmath>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;const int maxn = 350;
int n, num[maxn], tmp[maxn]; char str[maxn], che[maxn][2][maxn];class Big_integer {
private:int len, a[105];public:Big_integer() { memset(a, 0, sizeof a), len = 1; }~Big_integer() {};inline bool operator == (const Big_integer &x) const {if( this->len != x.len ) return false;for(int i = len; i; --i) if( this->a[i] != x.a[i] ) return false;return true;}inline bool operator < (const Big_integer &x) const {if( this->len != x.len ) return this->len < x.len;for(int i = len; i; --i) if( this->a[i] > x.a[i] ) return false;return (*this == x) == false;}inline bool operator > (const Big_integer &x) const {if( this->len != x.len ) return this->len > x.len;for(int i = len; i; --i) if( this->a[i] < x.a[i] ) return false;return (*this == x) == false;}inline Big_integer operator = (int x) {memset(a, 0, sizeof a), len = 0;while( x ) a[++len] = x % 10, x = x / 10;return *this;}inline Big_integer operator + (const Big_integer &x) const {Big_integer res;res.len = max(this->len, x.len) + 1;for(int i = 1; i <= res.len; ++i) {res.a[i] = this->a[i] + x.a[i] + res.a[i];if( res.a[i] > 9 ) res.a[i + 1] = res.a[i] / 10, res.a[i] = res.a[i] % 10;}while( res.a[res.len] == 0 && res.len > 1 ) --res.len;return res;}inline Big_integer operator / (const int &x) const {Big_integer res;res.len = this->len;for(int r = 0, i = len; i; --i) res.a[i] = (r * 10 + this->a[i]) / x, r = (r * 10 + this->a[i]) % x;while( res.a[res.len] == 0 && res.len > 1 ) --res.len;return res;}inline void read() {scanf("%s", str + 1), len = strlen(str + 1);for(int i = len; i; --i) a[i] = str[len - i + 1] ^ 48;}inline void prin() {for(int i = len; i; --i) printf("%d", a[i]); printf("\n");}inline void Transform(int *arr) {while( a[len] != 0 ) arr[++n] = a[1] & 1, *this = *this / 2;}
} a, dp[maxn][2][maxn];inline Big_integer Deep_fs(int fir, int pos, int tag, int limit) {Big_integer res;if( pos < 1 ) return (tag && fir > 0) ? res = 1 : res = 0;if( limit == 0 && che[pos][tag][fir] ) return dp[pos][tag][fir];for(int i = 0; i <= (limit ? num[pos] : 1); ++i) {tmp[pos] = i;if( fir == pos && i == 0 ) res = res + Deep_fs(fir - 1, pos - 1, tag, limit && i == num[pos]);else res = res + Deep_fs(fir, pos - 1, (tag && pos <= (fir >> 1)) ? tmp[fir - pos + 1] == i : tag, limit && i == num[pos]);}if( limit == 0 ) dp[pos][tag][fir] = res, che[pos][tag][fir] = 1;return res;
}int main(int argc, char const *argv[])
{a.read(), a.Transform(num), Deep_fs(n, n, 1, 1).prin();return 0;
}

轉(zhuǎn)載于:https://www.cnblogs.com/nanjoqin/p/11318859.html

總結(jié)

以上是生活随笔為你收集整理的[HNOI2002] Kathy 函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。