数位 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;
}

转载于:https://www.cnblogs.com/nanjoqin/p/11318859.html

[HNOI2002] Kathy 函数相关推荐

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

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

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

    排名函数是SQL Server2005新加的功能.在SQL Server2005中有如下四个排名函数row_number.rank.dense_rank和ntile,需要的朋友可以参考下. 排名函数是 ...

  3. C# 中奇妙的函数–6. 五个序列聚合运算(Sum, Average, Min, Max,Aggregate)

    今天,我们将着眼于五个用于序列的聚合运算.很多时候当我们在对序列进行操作时,我们想要做基于这些序列执行某种汇总然后,计算结果. Enumerable 静态类的LINQ扩展方法可以做到这一点 .就像之前 ...

  4. python中用什么函数读取字符串_Python(2)字符串的主要方法

    二.字符串方法 1. 获取字符串的长度,使用函数len() 1 a = "Hello, World!" 2 print(len(a)) 2. 删除字符串前后空格,使用函数strip ...

  5. mysql over rank_sql - MySQL中的Rank函数

    sql - MySQL中的Rank函数 我需要找出客户的排名. 在这里,我为我的要求添加了相应的ANSI标准SQL查询. 请帮我转换为MySQL. SELECT RANK() OVER (PARTIT ...

  6. Hive、Hadoop完全分布式安装,基本SQL,基本SQL,基本表结构,数据类型,函数,窗口函数,jion,查询和排序,beeline,文件格式及基本架构汇总

    目录 Hive简介 一.概述 二.Hive和数据库的比较 三.特点 Hadoop完全分布式安装 一.配置 二.安装步骤 Hive安装 一.概述 二.安装步骤 其他 一.Hive运行日志 二.Hive的 ...

  7. 数据库中自定义排序规则,Mysql中自定义字段排序规则,Oracle中自定义字段排序规则,decode函数的用法,field函数的用法

    数据库中自定义排序 场景:有一张banner表,表中有一个status字段,有0, 1, 2三个状态位,我想要 1,0,2的自定义排序(这里是重点),然后再进行之上对sequence字段进行二次排序( ...

  8. Mysql函数group_concat、find_in_set 多值分隔字符字段进行数据库字段值翻译

    Mysql函数group_concat.find_in_set进行数据库字段值翻译 场景 配方表:记录包含的原料 sources表示原料,字段值之间用逗号分隔 原料表:对应原料id和原料名称 现需要查 ...

  9. C++ 笔记(34)— C++ exit 函数

    当遇到 main 函数中的 return 语句时,C++ 程序将停止执行.但其他函数结束时,程序并不会停止.程序的控制将返回到函数调用之后的位置.然而,有时候会出现一些非常少见的情况,使得程序有必要在 ...

最新文章

  1. java socket modbus_Java modbus tcp 编程有懂得吗?给个示例看看。。。十分感谢。
  2. python内置对象的实现_Python 内置对象的实现
  3. docker for ubuntu安装
  4. AttributeError: 'Model' object has no attribute 'target_tensors'
  5. command line
  6. 国家开放大学2021春1129土木工程力学(本)题目
  7. 天才王垠惊人言论炸翻网友:相对论是假说,爱因斯坦是民科!
  8. linux中touch命令的作用,Linux中touch命令的作用是什么
  9. 批量更改数据库COLLATION
  10. R语言自然语言处理:文本分类
  11. 获取RenderedGeometry不对的处理
  12. Java基础-标识符
  13. ARCore快速入门--简介
  14. 手机浏览器看视频加载太慢怎么办,这5招用了提速快
  15. 他是发明声呐的物理天才,被妻子家暴后出轨守寡的师母,爱因斯坦却公开支持.........
  16. 电路与电子技术课程设计报告(正弦、方波-三角波、可调矩形波、可调锯齿波发生器)
  17. 华为无线设备配置不同业务VLAN的AP间快速漫游
  18. Android王者荣耀模拟金牌,荣耀战区修改方法 轻松获得省级金牌银牌
  19. php环境下安装并运行laravel教程
  20. php竞赛,PHP大赛

热门文章

  1. 基于Golang的简单web服务程序开发——CloudGo
  2. 如何在团队中做好Code Review
  3. 2022-2028年中国聚乳酸降解塑料行业市场运营格局及投资前景趋势报告
  4. 2022-2028年中国聚合物气体分离膜行业市场发展模式及投资前景分析报告
  5. C/C++ 编程规范(01 )— 排版
  6. 使用阿里云服务器安装docker,并用nginx示例
  7. 机器学习常用术语词汇表
  8. VTA:深度学习加速器堆栈
  9. python 遍历字符串
  10. Android studio 开发工具,试图预览工具不见了找会设置