zoukankan      html  css  js  c++  java
  • hdu 2089 不要62 【数位DP】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089

    数位DP模板题。測试板子

    代码:

    #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 N 12
    
    using namespace std;
    int bit[N];
    int dp[N][3];
    
    /*
          dp[i][0]:前i位不含不吉利数的个数。

       dp[i][1]:前i位不含不吉利数且i+1位是6的个数。

      dp[i][2]:前i位含不吉利数的个数。 */ int dfs(int pos, int st, bool flag) { if (pos == 0)return st == 2; if (flag&&dp[pos][st] != -1)return dp[pos][st]; int ans = 0; int u = flag ?

    9 : bit[pos]; for (int d = 0;d <= u;d++) { if (st == 2 || d == 4 || (st == 1 && d == 2)) ans += dfs(pos - 1, 2, flag || d<u); else if (d == 6) ans += dfs(pos - 1, 1, flag || d<u); else ans += dfs(pos - 1, 0, flag || d<u); } if (flag) dp[pos][st] = ans; return ans; } int solve(int n) { int len = 0; while (n) { bit[++len] = n % 10; n /= 10; } return dfs(len, 0, 0); } int main() { int n, m; memset(dp, -1, sizeof(dp)); while (~scanf("%d%d", &n, &m)) { if (!(n || m))return 0; printf("%d ", m - n + 1 - (solve(m) - solve(n - 1))); } return 0; }

  • 相关阅读:
    CTF-pwn-tips-zh_CN
    Linux 内核中 offset_of 和 container_of 宏的实现
    glibc2.26 -- tcache (2)
    glibc2.26 -- tcache (1)
    漏洞复现 -- 条件竞争 -- TOCTOU
    Linux 内核源码分析 -- read
    ospf lsa 4是不可替代的
    MPLS_Lab_3_AToM
    配置多链路捆绑PPP
    OSPF在转换LSA 5时的转发地址抑制 cyrus
  • 原文地址:https://www.cnblogs.com/wzjhoutai/p/7265833.html
Copyright © 2011-2022 走看看