[数位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 数 ...
随机推荐
- 029 c3p0的小测试
今天被问到这个问题,就实验了一下,后续会继续补充一些配置项的意思. 一:操作步骤 1.大纲 2.新建sql -- ---------------------------- -- Table struc ...
- Echarts官网展示
1.参考实例 http://echarts.baidu.com/examples/ 点击去的效果: 2.配置项手册 http://echarts.baidu.com/option.html#title ...
- day 42 mycql 数据类型
关于性别字段的存储数据类型选用 -- 性别字段 create table actor2 (id int not null auto_increment primary key,name char(32 ...
- java.io.File中字段的使用
File.pathSeparator指的是分隔连续多个路径字符串的分隔符,例如:Java -cp test.jar;abc.jar HelloWorld就是指“;” File.separa ...
- json数组,前后端传值问题,与data时间转毫秒
从json数组到ArrayList Gson gson = new Gson(); Car cars = gson.fromJson(result,new TypeToken<ArrayList ...
- laravel启动过程简单解析
:first-child{margin-top:0!important}img.plugin{box-shadow:0 1px 3px rgba(0,0,0,.1);border-radius:3px ...
- JavaEE 之 RESTful
1.RESTful a.定义:一种软件架构风格,设计风格而不是标准,只是提供了一组设计原则和约束条件.它主要用于客户端和服务器交互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等 ...
- 2501 矩阵距离 (bfs)
描述 给定一个N行M列的01矩阵 A,A[i][j] 与 A[k][l] 之间的曼哈顿距离定义为: dist(A[i][j],A[k][l])=|i-k|+|j-l| 输出一个N行M列的整数矩阵B,其 ...
- web服务-1、http协议的三次握手四次挥手
知识点:http协议:它是基于tcp协议的,浏览器访问服务器,服务器把资源回给浏览器,这个过程都是遵循http协议的,否则无法完成,http早些年是1.0版本,现在基本上都是1.1版本了,俩个版本的区 ...
- Codeforces Gym 101291C【优先队列】
<题目链接> 题目大意: 就是一道纯模拟题,具体模拟过程见代码. 解题分析:要掌握不同优先级的优先队列的设置.下面是对优先队列的使用操作详解: priority_queue<int& ...