HDU 3555 Bomb "digital DP"

Source: Internet
Author: User

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&LT;U);Else if(d = =4) ans + = DFS (pos-1,1, Flag | | D&LT;U);ElseAns + = DFS (pos-1,0, Flag | |    D&LT;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"

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.