[原创]HDU 5898&&2016 ACM/ICPC Asia Regional Shenyang Online/ odd-even number [数位 DP]【动态规划】
2016-09-18 22:01:52 Tabris_ 阅读数:316
博客爬取于 2020-06-14 22:43:16
以下为正文
版权声明:本文为 Tabris 原创文章,未经博主允许不得私自转载。
https://blog.csdn.net/qq_33184171/article/details/52578407
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5898
-----------------------------------------------------------.
odd-even number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 125 Accepted Submission(s): 66
Problem Description
For a number,if the length of continuous odd digits is even and the length of continuous even digits is odd,we call it odd-even number.Now we want to know the amount of odd-even number between L,R(1<=L<=R<= 9*10^18).
Input
First line a t,then t cases.every line contains two integers L and R.
Output
Print the output for each case on one line in the format as shown below.
Sample Input
2
1 100
110 220
Sample Output
Case #1: 29
Case #2: 36
Source
2016 ACM/ICPC Asia Regional Shenyang Online
--------------------------------------.
题目大意:
就是统计区间内满足连续奇数个数为偶数且连续偶数为奇数的数的个数
解题思路 :
很明显一道数位 DP
鄙人用的是记忆化搜索
开了 4 维数组
LL dp[30][3][30][3];
分别是位数 奇偶 正在判断的连续奇偶的长度 满不满足的状态
LL dfs(int pos,int pre,int x,int limit,int status,int lengh)
分别是位数/上一位的数字/上一位数字的奇偶性/数位的限制/满不满足的状态/正在判断的连续奇偶的长度
然后转移的时候注意的就是前导 0 的情况不要当成偶的数字给统计了 否则数会多
数位 DP 无非就三点
数组怎么开
记忆化搜索的参数
转移的过程
↑上面 3 点都解决了 相信数位 DP 的题目就解决了。
平时为了验证数位 DP 的正确性 在小数据的时候把记忆化注释掉了 交题的时候没改回来 就这样 TLE 了一发。。。GG
但也终于在比赛中 AC 了一道数位 DP 也算是小进步
附本题代码
--------------------------------.
1 | # include <stdio.h> |
[原创]HDU 5895&&2016 ACM/ICPC Asia Regional Shenyang Online1004 Mathematician QSC [矩阵加速+欧拉降幂]【数论】
[原创]HDU 5895&&2016 ACM/ICPC Asia Regional Shenyang Online1004 Mathematician QSC [矩阵加速 + 欧...
[原创]POJ 2142 The Balance [不定方程和最小的正整数解]【数论】
[原创]POJ 2142 The Balance [不定方程和最小的正整数解]【数论】 2016-09-16 17:15:30 Tabris_ 阅读数:1428 博客爬取于 2020-06...


