Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=3555
Test instructions: Last question is not 62 this is "do not 49"
Code:
#include <stdio.h>#include <ctime>#include <math.h>#include <limits.h>#include <complex>#include <string>#include <functional>#include <iterator>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <set>#include <map>#include <list>#include <bitset>#include <sstream>#include <iomanip>#include <fstream>#include <iostream>#include <ctime>#include <cmath>#include <cstring>#include <cstdio>#include <time.h>#include <ctype.h>#include <string.h>#include <assert.h>using namespace STD;#define Nusing namespace STD;intBit[n];Long Longdp[n][3];/* Dp[i][0]: The first I bit does not contain 49 of the number. DP[I][1]: The first I bit does not contain 49 number and i+1 bit is the number of 4. DP[I][2]: The first I bit contains 49 of the number. */Long LongDfsintPosintStBOOLFlag) {if(pos = =0)returnSt = =2;if(Flag && dp[pos][st]! =-1)returnDP[POS][ST];Long LongAns =0;intU = flag?9: Bit[pos]; for(intD =0;d <= u;d++) {if(St = =2|| (St = =1&& D = =9)) ans + = DFS (pos-1,2, Flag | | D<U);Else if(d = =4) ans + = DFS (pos-1,1, Flag | | D<U);ElseAns + = DFS (pos-1,0, Flag | | D<U); }if(flag) dp[pos][st] = ans;returnAns;}Long LongSolveLong LongN) {intLen =0; while(n) {Bit[++len] = nTen; N/=Ten; }returnDFS (Len,0,0);}intMain () {Long LongNintTscanf("%d", &t); while(t--) {scanf("%lld", &n);memset(DP,-1,sizeof(DP));printf("%lld\n", Solve (n)); }return 0;}
Copyright NOTICE: Reprint please indicate the source.
HDU 3555 Bomb "digital DP"