zoukankan      html  css  js  c++  java
  • 2018.10.22-ssoi3979荔枝丹(litchi)

    算法:搜索?????

    思路:

    经计算,共仅有C(27,9)=4686824种情况会对答案造成贡献,于是我们暴力枚举所有情况,再暴力在l,r中按位数f(枚举到的位数,bool 是否在左边界,bool是否在右边界)来爆搜,效率不会算玄学。

    代码:

    #include<bits/stdc++.h>
    #define il inline
    #define LL long long
    #define _(d) while(d(isdigit(ch=getchar())))
    using namespace std;
    LL l,r,tmp,tt,c[12],lb[20],rb[20];int ans;bool pd;
    il LL read(){LL x;char ch;_(!);x=ch-48;_()x=(x<<1)+(x<<3)+(ch^48);return x;}
    int f(int x,bool lpd,bool rpd){
        if(x==0)return 1;if(lpd==0&&rpd==0)return 1;
        if(lpd&&rpd&&lb[x]==rb[x]){if(!c[lb[x]])return 0;c[lb[x]]--;int res=f(x-1,1,1);c[lb[x]]++;return res;}
        if(lpd&&rpd){
            for(int i=lb[x]+1;i<=rb[x]-1;i++){
                if(!c[i])continue;c[i]--;int res=f(x-1,0,0);c[i]++;
                if(res>0)return 1;
            }
            if(c[lb[x]]){c[lb[x]]--;int res=f(x-1,1,0);c[lb[x]]++;if(res>0)return 1;}
            if(c[rb[x]]){c[rb[x]]--;int res=f(x-1,0,1);c[rb[x]]++;if(res>0)return 1;}return 0;
        }
        if(lpd){
            if(c[lb[x]]){c[lb[x]]--;int res=f(x-1,1,0);c[lb[x]]++;if(res>0)return 1;}
            for(int i=lb[x]+1;i<=9;i++){
                if(!c[i])continue;c[i]--;int res=f(x-1,0,0);c[i]++;
                if(res>0)return 1;
            }return 0;
        }
        if(rpd){
            if(c[rb[x]]){c[rb[x]]--;int res=f(x-1,0,1);c[rb[x]]++;if(res>0)return 1;}
            for(int i=0;i<=rb[x]-1;i++){
                if(!c[i])continue;c[i]--;int res=f(x-1,0,0);c[i]++;
                if(res>0)return 1;
            }return 0;
        }
        for(int i=0;i<=9;i++){
            if(!c[i])continue;c[i]--;int res=f(x-1,0,0);c[i]++;
            if(res>0)return 1;
        }return 0;
    }
    void dfs(int x,int now){
        if(x==tt+1){if(pd&&c[0]==tt-1&&c[1]==1)ans++;else if(c[0]!=tt)ans+=f(tt,1,1);return;}
        for(int j=now;j<=9;j++){c[j]++;dfs(x+1,j);c[j]--;}
    }
    int main()
    {
        l=read();r=read();if(r==1e18)pd=1,r--;tmp=l;while(tmp)lb[++tt]=tmp%10ll,tmp/=10ll;
        tt=0;tmp=r;while(tmp)rb[++tt]=tmp%10ll,tmp/=10ll;
        dfs(1,0);printf("%d
    ",ans);
      return 0;
    }
    View Code

    (测试,总方案数算错,总体爆炸心痛唉...)

  • 相关阅读:
    服务器变量 $_SERVER 详解
    PHP 函数功能参考
    ecshop后台0day漏洞原理+利用方法 XSS+Getshll
    CSRF漏洞原理说明与利用方法
    Drupal 远程命令执行漏洞(CVE-2018-7600)
    SSH登陆验证绕过漏洞(cve-2018-10933)
    单元二:建立和维护数据表
    单元一:认识数据库系统
    【 模块1 认识计算机 】1.2 认识微型计算机
    【 模块1 认识计算机 】 1.1走进计算机世界
  • 原文地址:https://www.cnblogs.com/Jessie-/p/9830450.html
Copyright © 2011-2022 走看看