HDU3652_ Digital DP

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=3652

Test instructions is the number of numbers that are divisible by 13 and contain "13" in an interval.

Definition Dp[len][mod][mark];

Where Len indicates the number of bits currently being processed or can be understood as the Len bit needs to be processed, the MoD represents the current total remainder (i.e. the remainder computed from the highest bit to the Len bit)

Mark plays the role of Mark

Mark==0 indicates that "13" has not appeared from the highest position to the I position;

The mak==1 indicates that "13" does not appear from the highest to the I bit, but the first bit is 1

mark==2 represents "13" from the highest bit to the I bit

Whether the flag flag has reached the upper limit

1#include <algorithm>2#include <iostream>3#include <cstring>4#include <cstdlib>5#include <cstdio>6#include <vector>7#include <ctime>8#include <queue>9#include <list>Ten#include <Set> One#include <map> A using namespacestd; - #defineINF 0x3f3f3f3f -typedefLong LongLL; the  - intbit[ the], dp[ the][ the][5]; - intDfs (intLenintMoDintMarkintflag) - { +     intsum =0; -     if(len = =0) +         returnMoD = =0&& Mark = =2; A     if(Flag && Dp[len][mod][mark] >=0) at         returnDp[len][mod][mark]; -     intTE = flag?9: Bit[len]; -      for(inti =0; I <= te; i++) -     { -         intMoD = (mod *Ten+ i)% -; -         intMark =Mark; in         if(Mark! =2&& I! =1) -Mark =0; to         if(Mark! =2&& i = =1) +Mark =1; -         if(Mark = =1&& i = =3) theMark =2; *Sum + = Dfs (Len-1, Mod, Mark, flag | | I <te); $     }Panax Notoginseng     if(flag) -Dp[len][mod][mark] =sum; the     returnsum; + } A intMain () the { +     intN; -      while(~SCANF ("%d", &N)) $     { $memset (bit,0,sizeof(bit)); -         intLen =0; -          while(n) the         { -Bit[++len] = n%Ten;WuyiN/=Ten; the         } -Memset (DP,-1,sizeofDP); Wucout<< Dfs (Len,0,0,0) <<Endl; -     } About     return 0; $}
View Code

HDU3652_ Digital DP

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.