zoukankan      html  css  js  c++  java
  • 淘金

    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <iostream>
    #include <algorithm>
    #include <map>
    #include <ctime>
    #include <queue>
    #define rint register int
    #define ll long long
    #define mem(a,b) memset(a,b,sizeof(a))
    using namespace std;
    const int mod=1e9+7;
    const int MOD=76543;
    
    ll n; int K;
    int t[15],he;
    
    ll num[15006],cnt[15006]; int con;
    
    struct HAHSHSHS
    {
        int first[MOD];
        int an[42006];ll ke[42006];
        int nt[42006],e,tt,i;
        void clear()
        {
            mem(first,-1);
        }
        int ifif(ll x)
        {
            tt=x%MOD;
            for(i=first[tt];i!=-1;i=nt[i])
                if(ke[i]==x)
                    return an[i];
            return -1;
        }
        void add(ll x,int ans)
        {
            tt=x%MOD;
            an[e]=ans;
            ke[e]=x;
            nt[e]=first[tt];
            first[tt]=e++;
        }
    }H;
    
    struct son
    {
        int x,y; ll v;
        son(){}
        son(int _x,int _y)
        {
            x=_x; y=_y;
            v=1LL*cnt[x]*cnt[y];
        }
        bool friend operator < (son a,son b)
        {
            return a.v<b.v;
        }
    };
    
    priority_queue<son> q;
    
    bool flag[12006][12006];
    
    bool cmp(ll a,ll b)
    {
        return a>b;
    }
    
    void dfs(int order,int las,ll now)
    {
        if(!now||now>n) return ;
        if(H.ifif(now)==-1)
            ++con,num[con]=now,H.add(now,con);
        if(!order) return ;
        int i;
        for(i=las;i<=9;++i)
            dfs(order-1,i,now*i);
    }
    
    ll f[15][2][20006];
    ll dp(int order,int limit,int lead,int id)
    {
        if(id<0) return 0;
        if(!order)
        {
            if(lead) return 0;
            return id==1;
        }
        if( limit==10 && f[order][lead][id]!=-1 )
            return f[order][lead][id];
        ll an=0; int i;
        if(lead)
            an+=dp(order-1,10,1,id);
        for(i=1;i<limit;++i)
            if(num[id]%i==0)
                an+=dp(order-1,10,0,H.ifif(num[id]/i));
        if(limit&&limit!=10&&num[id]%limit==0)
            an+=dp(order-1,t[order-1],0,H.ifif(num[id]/limit));
        if(limit==10)
            f[order][lead][id]=an;
        return an;
    }
    
    ll work()
    {
        rint i,j; ll an=0;
        
        ll x=n;
        while(x)
        {
            t[++he]=x%10;
            x/=10;
        }
        dfs(he,1,1);
        
        mem(f,-1);
        for(i=1;i<=con;++i)
            cnt[i]=dp(he,t[he],1,i);
        sort(cnt+1,cnt+1+con,cmp);
        
        q.push(son(1,1));
        son tt;
        while(K&&!q.empty())
        {
            tt=q.top(); q.pop();
            if(flag[tt.x][tt.y]) continue;
            flag[tt.x][tt.y]=1;
            an=(an+tt.v)%mod;
            q.push(son(tt.x+1,tt.y));
            q.push(son(tt.x,tt.y+1));
            --K;
        }
        return an%mod;
    }
    
    int main(){
        
        //freopen("in.in","r",stdin);
        //freopen("out.out","w",stdout);
        
        H.clear();
        
        scanf("%lld%d",&n,&K);
        cout<<work();
    }
    淘金
  • 相关阅读:
    html5 td中的5它空隙待解决
    转:能说明你的Javascript技术很烂的五个原因
    css字体中文、英文、Unicode名对照表
    相对定位一个例子,仿淘宝商品列表中的简单效果
    利用Javascript判断操作系统的类型
    百度web前端面试题之求两个数的最大公约数和最小公倍数
    程序员在群询问破解软件
    转:IE10初探
    学习js在线html(富文本)编辑器
    json学习笔记
  • 原文地址:https://www.cnblogs.com/A-LEAF/p/7776907.html
Copyright © 2011-2022 走看看