数位 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. [开源]OSharpNS 步步为营系列 - 4. 添加业务对外API

    什么是OSharp OSharpNS全称OSharp Framework with .NetStandard2.0,是一个基于.NetStandard2.0开发的一个.NetCore快速开发框架.这个 ...

  2. 编写antd配置表单组件

    编写antd配置表单组件 整体思路 抽取formitem的配置数组:包含组件类型.名称.label名称,相关的opts和扩展的opts,传递进入组件 组件通过Form.create()进行表单创建,能 ...

  3. Kubernetes 安全概念详解

    Kubernetes 安全框架 API 认证三关 • 访问K8S集群的资源需要过三关:认证.鉴权.准入控制• 普通用户若要安全访问集群API Server,往往需要证书.Token  或者用户名+密码 ...

  4. Window权限维持(三):服务

    如果未正确配置Windows环境中的服务或这些服务可以用作持久性方法,则这些服务可能导致权限提升.创建一个新的服务需要管理员级别的特权,它已经不是隐蔽的持久性技术.然而,在红队的行动中,针对那些在威胁 ...

  5. express捕获全局异常的三种方法

    场景 express的路由里抛出异常后,全局中间件没办法捕获,需要在所有的路由函数里写try catch,这坑爹的逻辑让人每次都要多写n行代码 官方错误捕获中件间代码如下 app.use(functi ...

  6. JPA笔记2 OneToMany

    package one_to_many; import java.util.HashSet; import java.util.Set; import javax.persistence.Cascad ...

  7. mac os catalina mongodb最新安装流程

    1.brew安装 不推荐用brew,因为现在mongodb闭源了,brew里已经搜索不到mongodb,不过还是可以用brew安装的,这篇就不写了. 2.官网下载 直接去官网下载一个zip,解压完放到 ...

  8. curl tftp libcurl 功能使用

    #include <curl/curl.h> static size_t read_callback(void *ptr, size_t size, size_t nmemb, void ...

  9. vue--购物车案例(小知识点总结)

    Html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  10. Scrum 冲刺第二篇

    我们是这次稳了队,队员分别是温治乾.莫少政.黄思扬.余泽端.江海灵 一.会议 1.1  26号站立式会议照片: 1.2  昨天已完成的事情 团队成员 任务内容 黄思扬 Web 端首页.内容管理页开发. ...