B-number
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): Accepted submission (s): 2866
Problem Descriptiona Wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the SUB-STR ing "all" and can be divided by 13. For example, and 2613 is wqb-numbers, but 143 and 2639 is not. Your task is to calculate how many wqb-numbers from 1 to n for a given integer n.
Inputprocess till EOF. There is one positive integer n (1 <= n <= 1000000000).
Outputprint each answer in a single line.
Sample Input131002001000
Sample Output1122
Authorwqb0039
Source of Asia regional Chengdu site--online Contest test Instructions:
Calculates the number of numbers within N that contain 13 and can be divisible by 13:
1 /*2 Memory Search + digital DP, not very understanding of this routine, Dp[i][j][k],i represents the number of bits, j for the remainder, k=0 that no 13,k=1 indicates that the end is 1,3 K=0 says that there are 13. A number divided by 13 can be the remainder of the first divided by 13 and then divided by the last few.4 */5#include <iostream>6#include <string>7#include <cstdio>8#include <cmath>9#include <cstring>Ten#include <algorithm> One#include <vector> A#include <iomanip> -#include <queue> -#include <stack> the using namespacestd; - intN; - intdp[ -][ -][3]; - intc[ -]; + intDfsintLne,intMoDintHaveintLim//whether Lim represents an upper limit - { + if(lne<=0)//There is no number of digits to return to the condition of compliance A returnmod==0&have==2; at if(!lim&&dp[lne][mod][have]!=-1)//there is no limit and has been accessed - returnDp[lne][mod][have]; - intNum=lim?c[lne]:9;//assuming that the bit is 2, the next one is 3, and if the bit is 1 now, then the next one is able to fetch 9, - //if the bit is 2, the next one can only fetch 3 - intans=0; - for(intI=0; i<=num;i++) in { - intNmod= (mod*Ten+i)% -;//See if we can divide the 13 evenly, and because it starts with the highest digit of the original number, to //in fact, this process is a division process . + intNhave=have ; - if(have==0&&i==1) nhave=1;//The end is not 1, and now it's 1. the if(have==1&&i!=1&&i!=3) nhave=0;//The end is 1, and now it's not 1. * if(have==1&&i==3) nhave=2;//The end is 1, and now it's 3. $Ans+=dfs (lne-1, Nmod,nhave,lim&&i==num);//Lim&&i==num, at the very beginning, the NUM removed was the highest,Panax Notoginseng //So if I is smaller than num, then the next one of I can reach 9, and I==num, the biggest can reach only, bit[pos-1] - } the if(!Lim) +Dp[lne][mod][have]=ans;//DP only records no finite values A returnans; the } + intMain () - { $ while(SCANF ("%d", &n)! =EOF) $ { -memset (dp,-1,sizeof(DP)); - intCnt=0; the while(n) - {Wuyic[++cnt]=n%Ten; theN/=Ten; - } Wuprintf"%d\n", DFS (CNT,0,0,1)); - } About return 0; $}
Digital DP HDU3652