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

最新文章

  1. Android获取可存储文件所有路径
  2. Tomcat7优化配置
  3. AS项目转到eclipse中方法
  4. GitHub 上有哪些完整的 iOS-App 源码值得参考
  5. jsPlumb
  6. 【125】固定IP的电脑配置无线路由
  7. vb.net中的SqlHelper
  8. Android invalidate()自动清屏,屏幕刷新
  9. Thinkphp kindeditor 内容转义
  10. 使用Express搭建服务器
  11. java 面向抽象编程的思想
  12. SpringSecurity 进行自定义Token校验
  13. Python爬虫入门教程 28-100 虎嗅网文章数据抓取 pyspider
  14. h5页面
  15. Linux创建用户与权限赋值
  16. Comedi的安装
  17. 开发uniapp必备
  18. 【Linux】人脸识别的封装
  19. 【powerBI】power pivot添加参数表
  20. ubuntu14.04(server amd64)免密码sudo

热门文章

  1. 微服务 SpringCloud + docker
  2. Docker学习4-学会如何让容器开机自启服务
  3. 知识图谱与Bert结合
  4. 架构设计系列-前端模式的后端(BFF)翻译PhilCal&#231;ado
  5. 汇总Anaconda与ROS冲突解决方法
  6. Spring Cloud Hystrix Dashboard熔断器-Turbine集群监控(六)
  7. WPF xmlns:i=&quot;http://schemas.microsoft.com/expression/2010/interactivity&quot;
  8. SQL Server like 字段
  9. C# 实现敏感词过滤
  10. 来点高逼格的,使用前端Sendmessage实现SSO