light oj 1205 - Palindromic Numbers 数位DP
思路:搜索的时候是从高位到低位,所以一旦遇到非0数字,也就确定了数的长度,这样就知道回文串的中心点。
代码如下:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#define ll long long
using namespace std;
ll dp[][][];
int bit[],num[];
ll dfs(int pos,int m,int s,bool f)
{
if(!pos) return ;
if(!f&&dp[pos][m][s]!=-) return dp[pos][m][s];
ll ans=;
int e=f?bit[pos]:;
for(int i=;i<=e;i++){
if(!s){
num[pos]=i;
ans+=dfs(pos-,m-!i,s||i,f&&i==e);
}
else{
int t=(m+)>>;
bool flag=m&?pos<t:pos<=t;
if(flag){
if(num[m+-pos]==i)
ans+=dfs(pos-,m,s,f&&i==e);
}
else{
num[pos]=i;
ans+=dfs(pos-,m,s,f&&i==e);
}
}
}
if(!f) dp[pos][m][s]=ans;
return ans;
}
ll cal(ll n)
{
int m=;
while(n){
bit[++m]=n%;
n/=;
}
return dfs(m,m,,);
}
int main()
{
int t,ca=;
ll a,b;
memset(dp,-,sizeof(dp));
scanf("%d",&t);
while(t--){
scanf("%lld%lld",&a,&b);
if(a>b) swap(a,b);
printf("Case %d: %lld\n",++ca,cal(b)-cal(a-));
}
return ;
}
light oj 1205 - Palindromic Numbers 数位DP的更多相关文章
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
- light 1205 - Palindromic Numbers(数位dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1205 题解:这题作为一个数位dp,是需要咚咚脑子想想的.这个数位dp方程可能不 ...
- LightOJ 1205 Palindromic Numbers
数位DP.... Palindromic Numbers Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %l ...
- codeforces 55D - Beautiful numbers(数位DP+离散化)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Beta Round #51 D. Beautiful numbers 数位dp
D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...
- poj 3252 Round Numbers(数位dp 处理前导零)
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
- uva 10712 - Count the Numbers(数位dp)
题目链接:uva 10712 - Count the Numbers 题目大意:给出n,a.b.问说在a到b之间有多少个n. 解题思路:数位dp.dp[i][j][x][y]表示第i位为j的时候.x是 ...
- SPOJ BALNUM - Balanced Numbers - [数位DP][状态压缩]
题目链接:http://www.spoj.com/problems/BALNUM/en/ Time limit: 0.123s Source limit: 50000B Memory limit: 1 ...
- SPOJ10606 BALNUM - Balanced Numbers(数位DP+状压)
Balanced numbers have been used by mathematicians for centuries. A positive integer is considered a ...
随机推荐
- hdu 2275 Kiki & Little Kiki 1
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2275 题意:n个操作 Push 入容器 Pop弹出一个 满足<=该数的最大的数(若没有输出No ...
- 九度oj 1184 二叉树遍历
原题链接:http://ac.jobdu.com/problem.php?pid=1184 简单的二叉树重建,遍历. 如下: #include<cstdio> #include<cs ...
- windows phone listbox虚拟化(下)
之前写过一篇关于listbox虚拟化的文章,那里采用的方法都是自己早期研究的一些思路,然后发现当数据很大的时候,其实性能效果还是不太理想,下面让我们来仔细想一想到底是基于什么原因,我们回去破坏默认的虚 ...
- linux 编译C应用程序的Makefile
CC=arm-linux-gcctarget=testsource=test.call: $(target)$(target): $(source) $(CC) -o $@ $<.PHONY: ...
- mysql查询重复
select * from tablename where id in ( select id from tablename group by id having count(id) ...
- 微软职位内部推荐-SDE II
微软近期Open的职位: Senior Software Development Engineer Job Title: Senior Development Engineer Division: V ...
- Ant学习---第三节:使用Ant实现一个最小的项目编译
1.编译 .java 文件,生成 .jar 包,代码如下: <?xml version="1.0" encoding="UTF-8"?> <p ...
- 四则运算小程序测试--c++--软件工程课
一.测试内容: 1.生成题目数是否准确?2.打印方式(列数l.行间距jj)是否准确?3.有无乘除法cc是否准确?4.数的范围fw是否准确?5.除法有无余数c是否准确?6.加减有无负数f是否准确? 二. ...
- 我教女朋友学编程Html系列(6)—Html常用表单控件
做过网页的人都知道,html表单控件十分重要.基本上我们注册会员.登录用户,都需要填写用户名.密码,那些框框都是表单控件. 本来今天就想写一些常用的html表单控件,于是开始搜资料,找到了一个网页,作 ...
- FushionCharts Free 的运用[2D/3D图表处理]
由于先前在一些论坛中谈论到这个插件的运用,留了一些QQ联系方式,最近老是被一些程序员“骚扰”,说是请教一些关于FushionChart Free图表的处理技术,先前还是比较乐意接受的,但发现后来一些完 ...