[Digital DP] HDU 4389 x Mod f (x)

Source: Internet
Author: User

The number in the range [a, B] can be divided by the number of digits and the total number.

Train of Thought: to avoid repeated states, the number of enumerative digits and 1 ~ 81

DP [site] [Sum] [mod] [wsh]

To the site bit, the number of digits is sum, and the remainder of the last digit is mod, And the last digit is wsh

Enumeration 1 ~ 81 is the answer.

Code:

# Include "cstdlib" # include "cstdio" # include "cstring" # include "cmath" # include "queue" # include "algorithm" # include "iostream" # define EPS 1e-8using namespace STD; // September 23, 2014 10: 06: 20int DP [12] [82] [82] [82], num [12]; int DFS (INT site, int sum, int mod, int wsh, int f) {If (Site = 0) return sum = wsh & mod = 0; If (! F & DP [site] [Sum] [mod] [wsh]! =-1) return DP [site] [Sum] [mod] [wsh]; int Len = f? Num [site]: 9; int ans = 0; For (INT I = 0; I <= Len; I ++) {ans + = DFS (site-1, sum + I, (mod * 10 + I) % wsh, wsh, F & I = Len);} If (! F) DP [site] [Sum] [mod] [wsh] = ans; return ans;} int solve (int x) {int CNT = 0; while (X) {num [++ CNT] = x % 10; X/= 10;} int ans = 0; For (INT I = 1; I <= 82; I ++) {ans + = DFS (CNT, I, 1);} return ans;} int main () {int T, CAS = 1; CIN> T; memset (DP,-1, sizeof (DP); While (t --) {int X, Y; scanf ("% d", & X, & Y ); if (x> Y) Swap (x, y); printf ("case % d: % d \ n", CAS ++, solve (y) -Solve (x-1);} return 0;} // September 23, 2014 10:12:11


[Digital DP] HDU 4389 x Mod f (x)

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.