数位 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. 【linux】查看GPU使用率

    nvidia-smi -l 1   每秒刷新一次

  2. Flink是如何实现exactly-once语义的

    转自:https://blog.csdn.net/xianpanjia4616/article/details/86375224 最少一次:断了之后 重新执行 再去重 严格一次:根据检查点,再执行一次 ...

  3. TP框架where条件和whereOr条件同时使用

    前言:where里面的条件是 && 的关系,whereOr里面的条件是 | | 的关系, 想要得到的效果: 1.筛选出is_deleted字段为0(未删除)的公告 2.筛选出全部状态为 ...

  4. Redis set集合

    Set操作.Set集合就是不允许重复的列表 (无序集合) sadd(name,values) # name对应的集合中添加元素 scard(name) # 获取name对应的集合中元素个数 sdiff ...

  5. java为什么要用类型擦除实现泛型?--c++,java,c# 的泛型是如何实现的

    所以总结一下c++,java,c#的泛型.c++的泛型在编译时完全展开,类型精度高,共享代码差.java的泛型使用类型擦出,仅在编译时做类型检查,在运行时擦出,共享代码好,但是类型精度不行.c#的泛型 ...

  6. Winforn中设置ZedGraoh的GraphPane恢复到初始比例大小

    场景 Winform中实现ZedGraph中曲线右键显示为中文: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100115292 ...

  7. 前端之:js

    JavaScript概述 ECMAScript和JavaScript的关系 1996年11月,JavaScript的创造者--Netscape公司,决定将JavaScript提交给国际标准化组织ECM ...

  8. 基于vue+springboot+docker网站搭建【九】负载均衡

    后台mall-admin 负载均衡 1.新启动一个mall-admin docker实例 docker run -p 9002:9001 --name mall-admin-9002 --link m ...

  9. vue-v-for

    1.v-for遍历数组和对象 <ul> <li v-for="item in array">{{item}}</li><br> &l ...

  10. web文件上传的总结(二)改变Apache默认post值来提高文件上传大小

    上传的文件大小大于2MB的解决方法 #默认apache 允许上大小2MB #技术经理-->修改apache默认配置  php.ini (授权) (1)复制 php.ini -> php1. ...