[Digital DP] HDU 3565 bi-peak number

Source: Internet
Author: User

Question:

For the range [x, y], determine the number of dual-peaks and the maximum value in the range.

A double-peak number is defined as a number that can be divided into two //// \ formats.

Ideas:

The number before the DP [site] [cur] [OK] site bit is that the cur status is OK.

There are 7 OK types

0: all preceding values are 0.

1: the first peak and only one number

2: the first peak is on the top (up or down)

3: the first peak is at the bottom of the peak (you can enter the next peak or continue)

4: The same 1 is the second peak

5: Same 2 is the second peak

6: Same as 3, but cannot enter the next peak

Code:

# Include "cstdlib" # include "cstdio" # include "cstring" # include "cmath" # include "queue" # include "algorithm" # include "iostream" using namespace STD; # define ll unsigned _ int64int DP [30] [10] [7]; int numx [30], numy [30]; int DFS (INT site, int cur, int OK, int FA, int FB) // judge {If (Site = 0) Return OK = 6? 0:-1; // status 6 indicates the number of valid if (! Fa &&! FB &&~ DP [site] [cur] [OK]) return DP [site] [cur] [OK]; // none of them are boundary int min = fa? Numx [site]: 0; // upper bound int max = FB? Numy [site]: 9; // lower bound int ans =-1; // Initial Value for (INT I = min; I <= max; I ++) {int TEP = 0; If (OK = 0 & I) TEP = 1; // deprecated 0 else if (OK = 1) {if (I> cur) TEP = 2; // go up to else TEP =-1; // cannot go} else if (OK = 2) {if (I> cur) TEP = 2; // continue with else if (I = cur) TEP =-1; // equal cannot take else TEP = 3; // down} else if (OK = 3) {if (I> cur) TEP = 4; // jump to the second else if (I = cur) // 0 cannot jump if it is equal, because 0 {if (I) TEP = 4; else TEP =-1;} else TEP = 3; // continue} else if (OK = 4 )// Same as {if (I> cur) TEP = 5; else TEP =-1;} else if (OK = 5) {if (I> cur) TEP = 5; else if (I = cur) TEP =-1; else TEP = 6;} else if (OK = 6) {if (I >= cur) TEP =-1; // you can only skip else TEP = 6;} If (TEP! =-1) {int sum = DFS (site-1, I, TEP, fa & I = min, FB & I = max ); // The maximum value after this end, if (sum! =-1) ans = max (ANS, sum + I); // Add this ratio} If (! Fa &&! FB) DP [site] [cur] [OK] = ans; // return ans;} int main () {int T, CAS = 1; cin> T; memset (DP,-1, sizeof (DP); While (t --) {ll X, Y; scanf ("% i64u % i64u ", & X, & Y); // note that to power 2 ^ 64, use unsigned 64-bit to read int CNT = 0; while (y) {CNT ++; numx [CNT] = x % 10; X/= 10; numy [CNT] = Y % 10; y/= 10;} int ans = DFS (CNT, 0, 0, 1, 1); printf ("case % d: % d \ n", CAS ++, ANS =-1? 0: ANS);} return 0 ;}


[Digital DP] HDU 3565 bi-peak number

Contact Us

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.