hdu3565 Bi-peak Number (有上界和下界的数位dp)
发布时间:2021-05-27 10:24:20 所属栏目:大数据 来源:网络整理
导读:Problem Description A peak number is defined as continuous digits {D0,D1 … Dn-1} (D0 0 and n = 3),which exist Dm (0 m n - 1) satisfied Di-1 Di (0 i = m) and Di Di+1 (m = i n - 1). A number is called bi-peak if it is a concatenation of t
|
Problem Description
A peak number is defined as continuous digits {D0,D1 … Dn-1} (D0 > 0 and n >= 3),which exist Dm (0 < m < n - 1) satisfied Di-1 < Di (0 < i <= m) and Di > Di+1 (m <= i < n - 1).
The score of a number is the sum of all digits. Love8909 is crazy about bi-peak numbers. Please help him to calculate the MAXIMUM score of the Bi-peak Number in the closed interval [A,B]. ? Input The first line of the input is an integer T (T <= 1000),which stands for the number of test cases you need to solve. Each case consists of two integers “A B” (without quotes) (0 <= A <= B < 2^64) in a single line. ? Output For the kth case,output “Case k: v” in a single line where v is the maximum score. If no bi-peak number exists,output 0. ? Sample Input 3 12121 12121 120010 120010 121121 121121? Sample Output
Case 1: 0
Case 2: 0
Case 3: 8
题意:定义"特殊数"为两次先上升后下降形成的数,且第一位大于等于0,没有前导零,问所有满足条件的数中,位数和最大的是多少。
思路:可以把两座山峰看做7个状态,0:还没有到第一个山的上坡 1:到了第一个山的上坡,但是还不能“转弯”,即不能向下折,后面也类似 2:任然是第一个山的山坡,但是可以“转弯” 3:到了第一个山坡的下坡,且可以“转弯” 4:到了第二个山的上坡,但是还不能“转弯” 5:到了第二个山的的上坡,且可以转弯 6:到了第二个山的下坡。
(编辑:新余站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐



