题意:给定x、y。为[x,y]之间有多少个数的偶数位和减去奇数位和等于一。

个位是第一位。

样例: 10=1-0=1 所以10是这种数

思路:数位dp[i][sum][ok] i位和为sum 是否含有前导0.

然后就是由于有负数 所以依据范围把0设置为100 然后最后和等于101则为所求的数。

代码:

#include"cstdlib"
#include"cstdio"
#include"cstring"
#include"cmath"
#include"stack"
#include"algorithm"
#include"iostream"
using namespace std;
int dp[12][200][2],num[12];
int fuck[2]={1,-1};
int dfs(int site,int sum,int ok,int f)
{
if(site==0)
{
if(ok==0) return 0;
return sum==101?1:0; //小处理 和为101
}
if(!f&&dp[site][sum][ok]!=-1) return dp[site][sum][ok];
int len=f?num[site]:9;
int ans=0;
for(int i=0;i<=len;i++)
{
if(ok==0)
{
if(i==0) ans+=dfs(site-1,sum,ok||i!=0,f&&i==len);
else ans+=dfs(site-1,sum+i*fuck[site%2],ok||i!=0,f&&i==len);
}
else
{
ans+=dfs(site-1,sum+i*fuck[site%2],ok||i!=0,f&&i==len);
}
}
if(!f) dp[site][sum][ok]=ans;
return ans;
}
int solve(int x)
{
if(x<0) return 0;
int cnt=0;
while(x)
{
num[++cnt]=x%10;
x/=10;
}
return dfs(cnt,100,0,1); //进入的时候 sum=100
}
int main()
{
int t;
scanf("%d",&t);
memset(dp,-1,sizeof(dp));
while(t--)
{
int x,y;
scanf("%d%d",&x,&y);
printf("%d\n",solve(y)-solve(x-1));
}
return 0;
}

[数位dp] spoj 10738 Ra-One Numbers的更多相关文章

  1. 【数位dp】CF 55D Beautiful numbers

    题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...

  2. 【数位DP】 HDU 4722 Good Numbers

    原题直通车: HDU  4722  Good Numbers 题意: 求区间[a,b]中各位数和mod 10==0的个数. 代码: #include<iostream> #include& ...

  3. SPOJ BALNUM - Balanced Numbers - [数位DP][状态压缩]

    题目链接:http://www.spoj.com/problems/BALNUM/en/ Time limit: 0.123s Source limit: 50000B Memory limit: 1 ...

  4. SPOJ BALNUM Balanced Numbers (数位dp)

    题目:http://www.spoj.com/problems/BALNUM/en/ 题意:找出区间[A, B]内所有奇数字出现次数为偶数,偶数字出现次数为计数的数的个数. 分析: 明显的数位dp题, ...

  5. 【SPOJ 2319】 BIGSEQ - Sequence (数位DP+高精度)

    BIGSEQ - Sequence You are given the sequence of all K-digit binary numbers: 0, 1,..., 2K-1. You need ...

  6. 【SPOJ 1182】 SORTBIT - Sorted bit squence (数位DP)

    SORTBIT - Sorted bit squence no tags Let's consider the 32 bit representation of all integers i from ...

  7. Balanced Numbers (数位dp+三进制)

    SPOJ - BALNUM 题意: Balanced Numbers:数位上的偶数出现奇数次,数位上的奇数出现偶数次(比如2334, 2出现1次,4出现1次,3出现两次,所以2334是 Balance ...

  8. 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP

    [BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...

  9. 找规律/数位DP HDOJ 4722 Good Numbers

    题目传送门 /* 找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one () http://www.cnblogs.com/crazyapple/p/3315436.html 数 ...

随机推荐

  1. Maya cmds filterExpand 列出 选择的 uvs vertices faces edges 等 component 类型

    Maya cmds filterExpand 列出 选择的 uvs vertices faces edges 等 component 类型 cmds.ls() 的 flags 中没有指明 uvs 等这 ...

  2. hdu1598 find the most comfortable road (枚举)+【并查集】

    <题目链接> 题目大意: XX星有许多城市,城市之间通过一种奇怪的高速公路SARS(Super Air Roam Structure---超级空中漫游结构)进行交流,每条SARS都对行驶在 ...

  3. 004.etcd集群部署-动态发现

    一 etcd发现简介 1.1 需求背景 在实际环境中,集群成员的ip可能不会提前知道.如使用dhcp自动获取的情况,在这些情况下,使用自动发现来引导etcdetcd集群,而不是指定静态配置,这个过程被 ...

  4. React Native 打包 Apk

    第一步:生成秘钥库 keytool -genkey -v -keystore opsmart-android-release-key.keystore -alias opsmart-android - ...

  5. redis+mysql

    redis和mysql要根据具体业务场景去选型 mysql:数据放在磁盘   redis:数据放在内存 redis适合放一些频繁使用,比较热的数据,因为是放在内存中,读写速度都非常快,一般会应用在下面 ...

  6. jquery实时获取时间

    $(document).ready(function(){ function time(){ var date=new Date(); var h=date.getHours(); var m=dat ...

  7. Centos6.5部署Rsyslog+LogAnalyzer中文乱码解决

    中文乱码 [root@log include]# pwd /zhang/app/loganalyzer-/src/include [root@log include]# vim functions_c ...

  8. 英语口语练习系列-C27-艺术品-辨别物体-黄昏的歌

    艺术品 a work of art Theory talent art gallery draw the sketch motivate students' interest full of imag ...

  9. luffy项目的接口开发

    处理跨域请求 主要的思路: 设置一个基于CORS的中间件来处理,关于跨域的产生与处理手段 settings.py: MIDDLEWARE = [ 'django.middleware.security ...

  10. [ZJOI2016]大森林

    Description: 小Y家里有一个大森林,里面有n棵树,编号从1到n 0 l r 表示将第 l 棵树到第 r 棵树的生长节点下面长出一个子节点,子节点的标号为上一个 0 号操作叶子标号加 1(例 ...