[数位dp] spoj 10738 Ra-One Numbers
题意:给定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的更多相关文章
- 【数位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 ...
- 【数位DP】 HDU 4722 Good Numbers
原题直通车: HDU 4722 Good Numbers 题意: 求区间[a,b]中各位数和mod 10==0的个数. 代码: #include<iostream> #include& ...
- SPOJ BALNUM - Balanced Numbers - [数位DP][状态压缩]
题目链接:http://www.spoj.com/problems/BALNUM/en/ Time limit: 0.123s Source limit: 50000B Memory limit: 1 ...
- SPOJ BALNUM Balanced Numbers (数位dp)
题目:http://www.spoj.com/problems/BALNUM/en/ 题意:找出区间[A, B]内所有奇数字出现次数为偶数,偶数字出现次数为计数的数的个数. 分析: 明显的数位dp题, ...
- 【SPOJ 2319】 BIGSEQ - Sequence (数位DP+高精度)
BIGSEQ - Sequence You are given the sequence of all K-digit binary numbers: 0, 1,..., 2K-1. You need ...
- 【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 ...
- Balanced Numbers (数位dp+三进制)
SPOJ - BALNUM 题意: Balanced Numbers:数位上的偶数出现奇数次,数位上的奇数出现偶数次(比如2334, 2出现1次,4出现1次,3出现两次,所以2334是 Balance ...
- 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
- 找规律/数位DP HDOJ 4722 Good Numbers
题目传送门 /* 找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one () http://www.cnblogs.com/crazyapple/p/3315436.html 数 ...
随机推荐
- 004 使用SpringMVC开发restful API二--编写用户详情
一:编写用户详情服务 1.任务 @PathVariable隐射url片段到java方法的参数 在url声明中使用正则表达式 @JsonView控制json输出内容 二:@PathVariable 1. ...
- Visual Studio 2019及其注册码
Visual Studio 2019 更快地进行代码编写.更智能地执行操作.使用同类最佳IDE 创建未来. 下载Visual Studio 使用从初始设计到最终部署的完整工具集 ...
- POJ 3140 Contestants Division 【树形DP】
<题目链接> 题目大意:给你一棵树,让你找一条边,使得该边的两个端点所对应的两颗子树权值和相差最小,求最小的权值差. 解题分析: 比较基础的树形DP. #include <cstdi ...
- CSS-选择器权重计算
权重计算规则 内联样式,如: style=" ",权值为1000. ID选择器,如:#content,权值为0100. 类,伪类和属性选择器,如.content,权值为0010. ...
- Linux 默认目录
/etc 存放系统管理所需要的配置文件和子目录 /home 一般用户的主目录 /usr 用户使用的系统目录和应用程序等信息 /bin 存放使用者经常使用的命令 如cp ls cat 等 /proc ...
- redis+mysql
redis和mysql要根据具体业务场景去选型 mysql:数据放在磁盘 redis:数据放在内存 redis适合放一些频繁使用,比较热的数据,因为是放在内存中,读写速度都非常快,一般会应用在下面 ...
- angular笔记_9
<style> .red{background:red} </style> 失去焦点 <input type="text" ng-model=&quo ...
- angular笔记_7
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Python datetime与timestamp之间的转换
# !!!! Python 2 datetime.datetime 对象没有timestamp方法! 在用Python处理datetime和timestamp的转换时发现在时区方面,Python的处理 ...
- HTML使用的几个小知识点
本文主要分享几个网页前端的几个基础知识点,用于零碎的html知识学习,同时也是在实践中的一些心得.最后给出了几个小例子. 1. 网页编程初识 掌握基本的html标签以及CSS语法 学会查看网页的源代码 ...