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 2094 产生冠军
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2094 产生冠军 Description 有一群人,打乒乓球比赛,两两捉对撕杀,每两个人之间最多打一场比 ...
- Douglas Crockford: entityify & deentityify
大神之字符与字符实体的相互转换方法 // & to & if (!String.prototype.entityify) { String.prototype.entityify = ...
- 初识java之Mina(一)
Apache Mina Server 是一个网络通信应用框架,也就是说,它主要是对基于 TCP/IP.UDP/IP协议栈的通信框架(当然,也可以提供 JAVA 对象的序列化服务.虚拟机管道通信服务等) ...
- iPhone的震动 基于SDK8.0 Swift实现
导入AudioToolbox.framework包 在swift文件中 import AudioToolbox AudioServicesPlaySystemSound(SystemSoundID. ...
- 37.altium designer中的class和rules?
在布局布线工程中,遇到复杂工程时,难免要进行class和rules的设置,经过试验证明,class和rules的子目录是有优先级的.
- 数据类型 swift
1整形 Int,Int8,Int16,Int32,Int64 UInt,UInt8,UInt16,UInt32,UInt64 其中Int,UInt始终和当前平台的原生字长相同(32位机,64位机) 查 ...
- 远航1617团队alpha版本分数分配与人员调动
一.根据项目开始初期的分数分配要求及项目发布后大家的讨论,我们对组内成员的分数分配如下: 刘昊岩 20.5 周 萱 20.0 林谋武 19.0 杨 帆 18.5 高小洲 21.0 谢勤政 21.5 ...
- camera render texture 游戏里的监控视角
Camera里: 新建render texture并拖入到target texture里 新建材质球 拖入render texture camera里的视角会在材质球上出现 新建一个pla ...
- using详解(C#)
using肯定所有人都用过,最简单的就是使用using引入命名空间,然后就是引入别名,简化输入,本文主要介绍第三种用法,即用using强制对象清理资源. 先看下面这段代码: try { using ( ...
- 前端之JavaScript第三天学习(8)-JavaScript-对象
JavaScript 中的所有事物都是对象:字符串.数字.数组.日期,等等. 在 JavaScript 中,对象是拥有属性和方法的数据. 属性和方法 属性是与对象相关的值. 方法是能够在对象上执行的动 ...