Palindromic Numbers LightOJ - 1205
题目大意:
求区间内的回文数个数
题目思路:
数位dp,先枚举前一半数字,然后填上相应的后一半数字。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#define MAXSIZE 1000005
#define LL long long using namespace std; LL dp[][][];
int temp[MAXSIZE],bit[MAXSIZE]; LL dfs(int pos,int st,int pre,int limit)
{
if(pos < )
return ;
if(!limit && dp[pos][st][pre]!=-)
return dp[pos][st][pre];
int len = limit?bit[pos]:;
LL ans = ;
for(int i=;i<=len;i++)
{
temp[pos] = i;
if(pre== && i==)
{
ans += dfs(pos-,st-,,i==len&&limit);
} else if(pos > st/) //枚举前一半
{
ans += dfs(pos-,st,,i==len&&limit);
} else if(temp[pos] == temp[st-pos+]) //填上后一半
{
ans += dfs(pos-,st,,i==len&&limit);
}
} if(!limit)
dp[pos][st][pre] = ans;
return ans;
} LL Solve(LL n)
{
int pos = ;
memset(dp,-,sizeof(dp));
while(n)
{
bit[++pos] = n%;
n /= ;
}
LL ans = dfs(pos,pos,,);
return ans;
} int main()
{
int T,cns=;
LL n,m;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld",&n,&m);
if(n > m)
swap(n,m);
LL ans = Solve(m) - Solve(n-);
printf("Case %d: %lld\n",cns++,ans);
}
return ;
}
Palindromic Numbers LightOJ - 1205的更多相关文章
- LightOJ 1205 Palindromic Numbers
数位DP.... Palindromic Numbers Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %l ...
- LightOJ - 1205:Palindromic Numbers (数位DP&回文串)
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...
- LightOJ - 1396 :Palindromic Numbers (III)(逐位确定法)
Vinci is a little boy and is very creative. One day his teacher asked him to write all the Palindrom ...
- lightoj 1205 数位dp
1205 - Palindromic Numbers PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 3 ...
- [暑假集训--数位dp]LightOj1205 Palindromic Numbers
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...
- Lightoj1205——Palindromic Numbers(数位dp+回文数)
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...
- xtu summer individual 1 E - Palindromic Numbers
E - Palindromic Numbers Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %l ...
- 【LightOJ - 1205】Palindromic Numbers
[链接]https://cn.vjudge.net/problem/LightOJ-1205 [题意] 求出L..R范围内的回文个数 [题解] 数位DP; 先求出1..x里面的回文串个数.则做一下前缀 ...
- light 1205 - Palindromic Numbers(数位dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1205 题解:这题作为一个数位dp,是需要咚咚脑子想想的.这个数位dp方程可能不 ...
随机推荐
- (链表 递归) leetcode 24. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head. You may not modify the value ...
- (基础)codeVs2235 机票打折
题目描述 Description .输入机票原价(3到4位的正整数,单位:元),再输入机票打折率(小数点后最多一位数字).编程计算打折后机票的实际价格(单位:元.计算结果要将个位数四舍五入到十位数“元 ...
- qml: 多级窗口visible现象;
多级窗口可以通过动态组件进行实现,也可以通过loader加载. 然而,在此要注意窗口显示.隐藏的顺序: 1.当窗口层级为主窗口 - 子窗口A --- 子窗口B: 这种模式, A是B的父窗口,那么在进行 ...
- Redash 安装部署
介绍 是一款开源的BI工具,提供了基于web的数据库查询和数据可视化功能. 官网:https://redash.io/ GitHub:https://github.com/getredash/reda ...
- ipv4转化为ipv6
十進制轉換成十六進位 IPV6為十六進位,所以十進制轉換成十六進位192=c0 168=a8192.168.1.1 轉成 16 進制為 c0.a8.01.01可以使用 Windows 工程版或是程式設 ...
- UEFI BIOS Rootkit Analysis
catalog . BIOS简介 . UEFI BIOS . EFI编程简介 . UEFI Rootkit 1. BIOS简介 BIOS("Basic Input Output System ...
- Hadoop问题:There are 0 datanode(s) running and no node(s) are excluded in this operation.
问题描述: org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /tmp/hadoop-yarn/staging/hado ...
- python Bootstarp框架和inconfont、font-awesome使用
http://www.bootcss.com/ http://www.runoob.com/bootstrap/bootstrap-panels.html 查找基本的没问题 https://www. ...
- Golang基础语法1
打开cmd命令窗口 保存,编译,执行: 1.保存到一个×××.go的文件(我这里保存到 E:\GoTest\hello.go 下) 2.编译,在命令提示符中执行命令: go build -o E ...
- ext Ext.grid.去除右边空白
1.当Scroll没有显示时,Ext.grid右边会显示一个空白间隔. 2.解决办法<View> <ext:GridView ForceFit="true" Sc ...