[数位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 数 ...
随机推荐
- Java程序员如何选择未来的职业路线
一.程序员的特性 技术出身的职场人特性很明显,与做市场.业务出身的职场人区别尤其明显.IT行业中常见的一些职场角色:老板.项目经理.产品经理.需求分析师.设计师.开发工程师.运维工程师等.开发工程师具 ...
- Number Sequence kmp
Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], .... ...
- Python图表数据可视化Seaborn:1. 风格| 分布数据可视化-直方图| 密度图| 散点图
conda install seaborn 是安装到jupyter那个环境的 1. 整体风格设置 对图表整体颜色.比例等进行风格设置,包括颜色色板等调用系统风格进行数据可视化 set() / se ...
- 20165235 祁瑛 2018-4 《Java程序设计》第六周学习总结
20165235 祁瑛 2018-4 <Java程序设计>第六周学习总结 教材学习内容总结 常用实用类 (一)1.String类是final类型的,String类型常量也是对象.2.可以使 ...
- Spring Security(15)——权限鉴定结构 RoleVoter
http://www.cnblogs.com/fenglan/p/5913432.html
- java日志的相关配置文件知识
w2bc.com/article/261758”“”“
- Python操纵Excel,数据库
操作excelxlwt:写入excel表格 ,用这个之前需要先导入模块 xlwt: import xlwtxlrd:读取excel,用这个之前需要先导入模块 xlwt:import xlrd 注意:e ...
- 直接引用vee-validate校验插件
直接在页面引用vee-validate 源文件下载地址:http://www.bootcdn.cn/vee-validate/ 官方api https://baianat.github.io/vee- ...
- oracle中两个时间类型的数据相减默认得到的是天数。
想要得到月份数,需要使用months_between函数. months_between(to_date('201707','yyyyMM'),to_date('201706','yyyyMM')) ...
- linux下执行.sh文件的方法和语法
linux下执行.sh文件的方法 .sh文件就是文本文件,如果要执行,需要使用chmod a+x xxx.sh来给可执行权限. 是bash脚本么 可以用touch test.sh ...