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 ...
随机推荐
- jQuery选项卡插件
html结构 <ul id="tabs" class="tabs"> <li data-tab="users">Us ...
- Go语言类型switch
switch还可以用于判断变量类型.使用方式为T.(type),即在变量后加上.(type).见代码: package main import ( "fmt" ) func mai ...
- iOS8 蓝牙设备的重连接(retrieve) Swift实现
今天App写到了蓝牙重连的阶段,以前针对sdk 6.0写的代码,蓝牙设备的回复是通过 - (void)retrievePeripherals:(NSArray *)peripheralUUIDs 然后 ...
- 在DNS管理器——用局域网IP指定你所起的域名名称
在服务器上面,进行以下相关的操作: 第一步:打开DNS管理器; 第二步:在“正向查找区域”添加域名为:icanyin.net; 第三步:添加主机pm,将域名pm.icanyin.net解析为IP地址: ...
- 41.使用Chipscope时如何防止reg_wire型信号被优化掉
随着FPGA设计复杂程度越来越高,芯片内部逻辑分析功能显得越来越重要.硬件层次上的逻辑分析仪价格十分昂贵,而且操作比较复杂.目前,FPGA芯片的两大供应商都为自己的FPGA芯片提供了软件层面上的逻辑分 ...
- Could not resolve placeholder
使用spring的<context:property-placeholder location="/WEB-INF/redis.properties"/>读取prope ...
- gitlab&fengoffice的ldap配置
1.fengoffice配置config/ldap_config.php $config_ldap = array ( 'binddn' => 'cn=admin,dc=xxx,dc=xxx', ...
- 阿里云无线&前端团队是如何基于webpack实现前端工程化的
背景 前端经历了初期的野蛮生长(切图,写简单的特效)——为了兼容浏览器兼容性而出现的各种类库(JQUERY,YUI等——mv*(饱暖思淫欲,代码多了,也就想到怎样组织代码结构,backbone,ang ...
- Oracle数据库中文乱码问题
最近碰到Oracle乱码问题,刚开始甚是头疼,以前在合肥出差的时候,这种问题也碰到过,当时直接抛给了“乌压压一片”(一个搞数据的同事儿),这次没办法躲过,只好硬着头皮上.虽然我这次碰到的是Oracle ...
- 【Ural】【1519】Formula 1
插头DP 本题为CDQ<基于连通性状态压缩的动态规划的……(我忘了)>里的例题!(嗯就是这样……) 先膜拜一下ccy大神……http://blog.sina.com.cn/s/blog_5 ...