zoukankan      html  css  js  c++  java
  • HDU

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<time.h>
    #include<iostream>
    #include<ctype.h>
    #include<map>
    #include<set>
    #include<string>
    #include<vector>
    #include<algorithm>
    #include<stdlib.h>
    #include<queue>
    #include<stack>
    using namespace std;
    #define LL long long
    LL dp[45][45][3],num[45];
    LL dfs(int pos,int mod,int st,int limit)//pos为数位从高位开始枚举(达到上限再枚举下一位),mod为对13求余,初始为0,st为状态,初始为0,limit为是否达到上限,1达到上限,0没有达到上限继续枚举
    {
        if(pos<0)
        return mod==0&&st==2;
        if(!limit&&dp[pos][mod][st]!=-1)
            return dp[pos][mod][st];
        int len=limit?num[pos]:9;//判断上一位是否到上限,若达到则只能枚举到num【pos】,否则可以枚举0——9
        int modx,stx;
        LL ans=0;
        for(int i=0;i<=len;i++)
        {
            modx=(mod*10+i)%13;
            stx=st;
            if(st==1&&i!=1)
                stx=0;
            if(st==0&&i==1)
                stx=1;
            if(st==1&&i==3)
                stx=2;
            ans+=dfs(pos-1,modx,stx,limit&&i==len);
        }
        if(!limit)//没有达到上限的都要存储一下该状态下的符合条件数;
            dp[pos][mod][st]=ans;
        return ans;
    
    }
    LL sv(LL a)
    {
        int len=0;
        memset(dp,-1,sizeof(dp));
        memset(num,-1,sizeof(num));
        while(a)
        {
            num[len++]=a%10;
            a/=10;
        }
        dfs(len-1,0,0,1);
    }
    int main()
    {
        LL n;
        while(~scanf("%lld",&n))
        {
            LL ee=sv(n);
            printf("%lld
    ",ee);
        }
    }
  • 相关阅读:
    1951: [Sdoi2010]古代猪文
    BZOJ 1911: [Apio2010]特别行动队[斜率优化dp]
    BZOJ 2038: [2009国家集训队]小Z的袜子(hose)&&莫队算法
    gdb命令整理
    1833: [ZJOI2010]count 数字计数
    1227: [SDOI2009]虔诚的墓主人
    P3197 [HNOI2008]越狱
    3505: [Cqoi2014]数三角形
    P3414 SAC#1
    3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛
  • 原文地址:https://www.cnblogs.com/nr1999/p/9401262.html
Copyright © 2011-2022 走看看