dlk 模板

struct DLX {
    int n , m,size;
    int U[N],D[N],R[N],L[N],row[N],col[N];
    int ans[N],S[N];
    int ansd;

    void init(int a,int b) {
        n = a;
        m = b;
        for(int i=0; i<=m; i++) {
            S[i] = 0;
            U[i] = D[i] = i;
            L[i] = i-1;
            R[i] = i+1;
        }
        R[m] = 0;
        L[0] = m;
        size = m;
        for(int i=1; i<=n; i++) ans[i] = -1;
    }

    void addRow(int r,int c) {
        ++S[col[++size]=c];
        row[size] = r;
        D[size] = D[c];
        U[D[c]] = size;
        U[size] = c;
        D[c] = size ;
        if(ans[r]<0)
            ans[r] =  L[size] = R[size] = size;
        else {
            R[size] = R[ans[r]];
            L[R[ans[r]]] = size;
            L[size] = ans[r];
            R[ans[r]] = size;
        }
    }

    void remove (int c) {
        for(int i= D[c]; i!=c; i=D[i]) {
            L[R[i]] = L[i];
            R[L[i]] = R[i];
        }
    }

    void resume(int c) {
        for(int i = U[c]; i!=c; i=U[i]) {
            L[R[i]]=R[L[i]] = i;
        }
    }

    bool v[N];

    int f() {  //精确覆盖区估算剪枝

        int ret = 0;
        for(int c =R[0]; c!=0; c=R[c])
            v[c] = true;
        for(int c = R[0]; c!=0; c=R[c]) {
            if(v[c]) {
                ret++;
                v[c] = false;
                for(int i=D[c]; i!=c; i=D[i]) {
                    for(int j=R[i]; j!=i; j=R[j]) {
                        v[col[j]]=false;
                    }
                }
            }
        }
        return ret;
    }

    void dance(int d) {
        if(d+f()>=ansd) return ;
        if(R[0]==0) {
            if(ansd>d)
                ansd = d;
            return;
        }

        int c = R[0];
        for(int i=R[0]; i!=0; i=R[i]) {
            if(S[i]<S[c]) {
                c=i;
            }
        }

        for(int i=D[c]; i!=c; i=D[i]) {
            remove(i);
            for(int j=R[i]; j!=i; j=R[j])
            remove(j);
            dance(d+1);
            for(int j=L[i]; j!=i; j=L[j])
            resume(j);
            resume(i);
        }
    }
} g;

转载于:https://www.cnblogs.com/lytwajue/p/6936194.html

最后一段:StatusCode setUnsupSegParam(const float defectThreshold, const float nonDefectThreshold, const unsigned int moduleIdx); /** * @brief Creates an infer engine for model package inference. * @param [in] modelPath The path to the model package exported from Mech-DLK. * @return See @ref StatusCode for details. */ StatusCode create(const std::string& modelPath); /** * @brief Loads the model into memory. * @return See @ref StatusCode for details. * @note When the type of the infer device is GpuOptimization, it may take 1-5 minutes to * optimize the model package. */ StatusCode load(); /** * @brief Makes image inference using the model package inference engine. * @param [in] images See @ref MMindImage for details. * @return See @ref StatusCode for details. */ StatusCode infer(const std::vector<MMindImage>& images); /** * @brief Gets the model inference result. * @param [in] results See @ref MMindResult for details. * @return See @ref StatusCode for details. */ StatusCode getResults(std::vector<MMindResult>& results); /** * @brief Draws all the model results onto the images. * @param [in] MMindImage See @ref MMindImage for details. * @return See @ref StatusCode for details. */ StatusCode resultVisualization(std::vector<MMindImage>& images); /** * @brief Draws the model results of the specified index onto the images. * @param [in] MMindImage See @ref MMindImage for details. * @param [in] moduleIdx Specified module index in the model package. * @return See @ref StatusCode for details. */ StatusCode moduleResultVisualization(std::vector<MMindImage>& images, const unsigned int moduleIdx); /** * @brief Gets the model type list. * @return See @ref DeepLearningAlgoType for details. */ std::vector<DeepLearningAlgoType> getDeepLearningAlgoTypes() const; /** * @brief Releases the memory of the model package inference engine. */ void release(); MMindInferEngine(const MMindInferEngine& rhs) = delete; MMindInferEngine(MMindInferEngine&& rhs); MMindInferEngine& operator=(const MMindInferEngine& rhs) = delete; MMindInferEngine& operator=(MMindInferEngine&& rhs); ~MMindInferEngine(); private: struct Impl; std::unique_ptr<Impl> _pImpl; }; } // namespace mmind::dl 好了 绑定吧
03-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值