数位 DP 套路题,求二进制下区间内回文串个数。

设 dp[][][] 表示到第几位时,是否为回文数,去掉前导零后共几位。之后到边界时判断是否为回文数计入贡献。

一开始不知道答案统计要高精,于是后来就自闭了。

#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;
}

[HNOI2002] Kathy 函数的更多相关文章

  1. bzoj 1223: [HNOI2002]Kathy函数 数位DP 高精度

    1223: [HNOI2002]Kathy函数 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 207  Solved: 90[Submit][Stat ...

  2. [bzoj1223] [HNOI2002]Kathy函数

    首先由题解可得TAT,f(i)=i当且仅当i在二进制下为回文串. 那么问题就变成了1~n中有多少个二进制下的回文串. 把m转成2进制后就是正常的统计了= =. f[i]表示二进制下,有多少个i位的回文 ...

  3. 洛谷P2235 [HNOI2002]Kathy函数

    传送门 题解 // luogu-judger-enable-o2 //minamoto #include<cstdio> #include<cstring> using nam ...

  4. 【题解】Kathy函数 [BZOJ1223] [P2235] [HNOI2002]

    [题解]Kathy函数 [BZOJ1223] [P2235] [HNOI2002] 这几疯狂刷了数位\(dp\)的题,到这道题时被卡了一天,一看大佬的讲解发现居然是求回文数╮(╯_╰)╭ 感觉被大佬狠 ...

  5. 洛谷$P$2235 $Kathy$函数 $[HNOI2002]$ 数位$dp$

    正解:数位$dp$ 解题报告: 传送门$qwq$ $HNOI$的题从02年就这么神了嘛$QAQ$,,, 嗷对了这题如果看出了一个结论就是个数位$dp$板子,,,?但是结论很神我$jio$得挺难看出来的 ...

  6. 数位DP学习笔记

    数位DP学习笔记 什么是数位DP? 数位DP比较经典的题目是在数字Li和Ri之间求有多少个满足X性质的数,显然对于所有的题目都可以这样得到一些暴力的分数 我们称之为朴素算法: for(int i=l_ ...

  7. Noip前的大抱佛脚----赛前任务

    赛前任务 tags:任务清单 前言 现在xzy太弱了,而且他最近越来越弱了,天天被爆踩,天天被爆踩 题单不会在作业部落发布,所以可(yi)能(ding)会不及时更新 省选前的练习莫名其妙地成为了Noi ...

  8. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  9. SQL2005四个排名函数(row_number、rank、dense_rank和ntile)的比较

    排名函数是SQL Server2005新加的功能.在SQL Server2005中有如下四个排名函数: .row_number .rank .dense_rank .ntile 下面分别介绍一下这四个 ...

随机推荐

  1. python运维开发常用模块(8)EXCEL操作模块XlsxWriter

    1.excel介绍 Excel是当今最流行的电子表格处理软件,支持丰富的计算函数及 图表,在系统运营方面广泛用于运营数据报表,比如业务质量.资源利 用.安全扫描等报表,同时也是应用系统常见的文件导出格 ...

  2. Zookeeper 到底能帮我们解决哪些问题?

    Zookeeper 从设计模式角度来看,是一个基于观察者模式设计的分布式服务管理框架,它负责存储和管理大家都关心的数据,然后接受观察者的注册,一旦这些数据的状态发生变化,Zookeeper 就将负责通 ...

  3. Preface_英语

    这是一本游戏指南.没错,你没有 看错,这就是一本游戏指南.当然,这 本指南针对的只是名为"英文"的游戏. 把英文和电子游戏比较一下,我们 会发现,这两者有惊人的相似之处. 第一,它 ...

  4. locally weighted regression - CS229

    欠拟合和过拟合 看下方的三张图 第一幅拟合为了 y=θ0+θ1xy=θ0+θ1x 的一次函数 第二幅拟合为了y=θ0+θ1x+θ2x2y=θ0+θ1x+θ2x2 的二次函数 第三幅拟合为了 y=∑5j ...

  5. 关于Idea突然无法输入的诡异问题解决

    问题描述 最近加班把自己的装有Debian的笔记本带到公司,使用Idea写代码的时候,突然间无法输入,ctrl与tab还可用,重启Idea能得到一阵的解决 解决参考 如果是Linux平台,请考虑是否是 ...

  6. IDA分析时添加新的C语言结构体

    View - Open Subviews - Local Type - INSERT键 - 输入新结构体 - 右击"Synchornize to idb" 之后再分析处按 T 就可 ...

  7. SAP PI开发手册-ERP发布服务供外部系统调用(sproxy代理类)

    转自:https://www.cnblogs.com/fanjb/p/10829858.html 一.      接口内容 接口详细信息 1.  字段对应关系 发送字段对应关系 返回字段对应关系 2. ...

  8. UWP使用TreeView

    这个帖子本来是不想写的,但是感觉网上类似的也没有,对于小白可能有点用,于是想着还是写一下吧. 写之前想说下,UWP其实并没有死掉,对于win10来说,以后的新设备肯定是支持UWP的,而且微软一直在完善 ...

  9. 博文与文档发布玩法:Github + MWeb + 语雀 + Cnbolgs

    本文会说两个话题, 1,如何将 Github 上的文档(如:dotnet-campus/doraemon-pocket: 哆啦A梦的口袋 - 收集效率工具与站点)发布到语雀. 2,如何在本地使用 Ma ...

  10. .NET Core RabbitMQ探索(2)——RabbitMQ的Exchange

    实际上,RabbitMQ的生产者并不会直接把消息发送给队列,甚至生产者都不知道消息是否会被发送给一个队列.对于生产者而言,它们只能把消息发送到Exchange,一个Exchange所完成的工作相当简单 ...