# [Digital dp] spoj 10738 Ra-One Numbers, spoj10738

Source: Internet
Author: User

[Digital dp] spoj 10738 Ra-One Numbers, spoj10738

Given x and y, the number of even digits between [x, y] is equal to or equal to one minus odd digits.

One digit is the first.

Example: 10 = 1-0 = 1 so 10 is such a number

Idea: digit dp [I] [sum] [OK] I bit and sum whether there is a leading 0.

Then, because there is a negative number, 0 is set to 100 Based on the range, and then the last and equal to 101 are the numbers.

Code:

[Cpp]View plaincopyprint?
1. # Include "cstdlib"
2. # Include "cstdio"
3. # Include "cstring"
4. # Include "cmath"
5. # Include "stack"
6. # Include "algorithm"
7. # Include "iostream"
8. Using namespace std;
9. Int dp   , num ;
10. Int fuck  = {1,-1 };
11. Int dfs (int site, int sum, int OK, int f)
12. {
13. If (site = 0)
14. {
15. If (OK = 0) return 0;
16. Return sum = 101? 1:0; // The sum of small processing and 101
17. }
18. If (! F & dp [site] [sum] [OK]! =-1) return dp [site] [sum] [OK];
19. Int len = f? Num [site]: 9;
20. Int ans = 0;
21. For (int I = 0; I <= len; I ++)
22. {
23. If (OK = 0)
24. {
25. If (I = 0) ans + = dfs (site-1, sum, OK | I! = 0, f & I = len );
26. Else ans + = dfs (site-1, sum + I * fuck [site % 2], OK | I! = 0, f & I = len );
27. }
28. Else
29. {
30. Ans + = dfs (site-1, sum + I * fuck [site % 2], OK | I! = 0, f & I = len );
31. }
32. }
33. If (! F) dp [site] [sum] [OK] = ans;
34. Return ans;
35. }
36. Int solve (int x)
37. {
38. If (x <0) return 0;
39. Int cnt = 0;
40. While (x)
41. {
42. Num [++ cnt] = x % 10;
43. X/= 10;
44. }
45. Return dfs (cnt, 100, 0, 1); // sum =
46. }
47. Int main ()
48. {
49. Int t;
50. Scanf ("% d", & t );
51. Memset (dp,-1, sizeof (dp ));
52. While (t --)
53. {
54. Int x, y;
55. Scanf ("% d", & x, & y );
56. Printf ("% d \ n", solve (y)-solve (x-1 ));
57. }
58. Return 0;
59. }

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.