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);
        }
    }
  • 相关阅读:
    剑指17.树的子结构
    剑指16.合并两个排序的链表
    剑指15.反转链表
    剑指14.链表中倒数第k个结点
    剑指13.调整数组顺序使奇数位于偶数前面
    剑指12.数值的整数次方
    剑指11.二进制中1的个数
    剑指10.矩形覆盖
    剑指09.变态跳台阶
    JS 中动态创建json,动态为json添加属性、属性值
  • 原文地址:https://www.cnblogs.com/nr1999/p/9401262.html
Copyright © 2011-2022 走看看