最长 K 顺序递增子序列

2024-04-26

为什么我创建了一个重复的线程

阅读后我创建了这个线程允许有 K 个例外的最长递增子序列 https://stackoverflow.com/questions/56155854/longest-increasing-subsequence-with-k-exceptions-allowed。我意识到问这个问题的人并没有真正理解这个问题,因为他指的是一个link https://www.geeksforgeeks.org/longest-increasing-subarray-with-one-change-allowed/这解决了“允许一次更改的最长递增子数组”问题。所以他得到的答案实际上与LIS问题无关。

问题描述

假设有一个数组A给出长度N。 找到最长的递增子序列K允许例外。

Example
1) N=9,K=1

A=[3,9,4,5,8,6,1,3,7]

答案:7

解释:

最长递增子序列为:3,4,5,8(或6),1(例外),3,7 -> 总计=7

  1. N=11,K=2

A=[5,6,4,7,3,9,2,5,1,8,7]

答案:8

到目前为止我所做的...

如果 K=1,则只允许一种例外。如果计算最长递增子序列的已知算法为O(NlogN)用来 (点击这里查看这个算法 https://www.geeksforgeeks.org/longest-monotonically-increasing-subsequence-size-n-log-n/),然后我们可以为数组 A 的每个元素计算从 A[0] 到 A[N-1] 的 LIS。我们将结果保存在一个新数组中L有尺寸N。查看示例 n.1,L 数组将是:L=[1,2,2,3,4,4,4,4,5]。

使用相反的逻辑,我们计算数组R,其中每个元素包含当前从N-1到0的最长递减序列。

除了一个例外,LIS 只是sol=max(sol,L[i]+R[i+1]), where sol初始化为溶胶=L[N-1]。 所以我们计算从 0 到索引的 LISi(例外),然后停止并启动新的 LIS,直到N-1.

A=[3,9,4,5,8,6,1,3,7]

L=[1,2,2,3,4,4,4,4,5]

R=[5,4,4,3,3,3,3,2,1]

Sol = 7

->逐步解释:

init: sol = L[N]= 5

i=0 : sol = max(sol,1+4) = 5 
i=1 : sol = max(sol,2+4) = 6
i=2 : sol = max(sol,2+3) = 6
i=3 : sol = max(sol,3+3) = 6
i=4 : sol = max(sol,4+3) = 7
i=4 : sol = max(sol,4+3) = 7
i=4 : sol = max(sol,4+2) = 7
i=5 : sol = max(sol,4+1) = 7

复杂性:O( NlogN + NlogN + N ) = O(NlogN)

因为数组R, L需要 NlogN 时间来计算,我们还需要 θ(N) 才能找到sol.

k=1问题的代码

#include <stdio.h>
#include <vector>

std::vector<int> ends;

int index_search(int value, int asc) {
    int l = -1;
    int r = ends.size() - 1;
    while (r - l > 1) { 
        int m = (r + l) / 2; 
        if (asc && ends[m] >= value) 
            r = m; 
        else if (asc && ends[m] < value)
            l = m;
        else if (!asc && ends[m] <= value)
            r = m;
        else
            l = m;
    } 
    return r;
}

int main(void) {
    int n, *S, *A, *B, i, length, idx, max;

    scanf("%d",&n);
    S = new int[n];
    L = new int[n];
    R = new int[n];
    for (i=0; i<n; i++) {
        scanf("%d",&S[i]);
    }

    ends.push_back(S[0]);
    length = 1;
    L[0] = length;
    for (i=1; i<n; i++) {
        if (S[i] < ends[0]) {
            ends[0] = S[i];
        }
        else if (S[i] > ends[length-1]) {
            length++;
            ends.push_back(S[i]);
        }
        else {
            idx = index_search(S[i],1);
            ends[idx] = S[i];
        }
        L[i] = length;
    }

    ends.clear();
    ends.push_back(S[n-1]);
    length = 1;
    R[n-1] = length;
    for (i=n-2; i>=0; i--) {
        if (S[i] > ends[0]) {
            ends[0] = S[i];
        }
        else if (S[i] < ends[length-1]) {
            length++;
            ends.push_back(S[i]);
        }
        else {
            idx = index_search(S[i],0);
            ends[idx] = S[i];
        }
        R[i] = length;
    }

    max = A[n-1];
    for (i=0; i<n-1; i++) {
        max = std::max(max,(L[i]+R[i+1]));
    }

    printf("%d\n",max);
    return 0;
}

泛化到 K 个异常

我提供了 K=1 的算法。我不知道如何更改上述算法以适用于 K 个异常。如果有人能帮助我,我会很高兴。


本回答修改自我的答案 https://cs.stackexchange.com/questions/118858/how-can-ideas-like-lagrange-multipliers-and-penalty-method-be-applied-for-solvin/118859#118859计算机科学 Stackexchange 上的类似问题。

最多有 k 个例外的 LIS 问题允许使用拉格朗日松弛的 O(n log² n) 算法。当 k 大于 log n 时,这会在 O(nk log n) DP 上渐近改进,我们也会对此进行简要解释。

Let DP[a][b] denote the length of the longest increasing subsequence with at most b exceptions (positions where the previous integer is larger than the next one) ending at element b a. This DP is not involved in the algorithm, but defining it makes proving the algorithm easier.

为了方便起见,我们假设所有元素都是不同的,并且数组中的最后一个元素是其最大值。请注意,这并不限制我们,因为我们只需将 m / 2n 添加到每个数字的第 m 次出现,并将无穷大附加到数组并从答案中减去 1。令 V 为排列,其中 1

为了解决 O(nk log n) 的问题,我们保持了 DP[a][b] 的不变式,即 b

我们有 DP[i][j] = 1 + max(DP[i'][j], DP[x][j-1]) 其中我们遍历 i', x

这是该算法的 C++ 实现。请注意,此实现并不假设数组的最后一个元素是其最大值,或者数组不包含重复项。


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

// Fenwick tree for prefix maximum queries
class Fenwick {
    private:
        vector<int> val;
    public:
        Fenwick(int n) : val(n+1, 0) {}

        // Sets value at position i to maximum of its current value and 
        void inc(int i, int v) {
            for (++i; i < val.size(); i += i & -i) val[i] = max(val[i], v);
        }

        // Calculates prefix maximum up to index i
        int get(int i) {
            int res = 0;
            for (++i; i > 0; i -= i & -i) res = max(res, val[i]);
            return res;
        }
};

// Binary searches index of v from sorted vector
int bins(const vector<int>& vec, int v) {
    int low = 0;
    int high = (int)vec.size() - 1;
    while(low != high) {
        int mid = (low + high) / 2;
        if (vec[mid] < v) low = mid + 1;
        else high = mid;
    }
    return low;
}

// Compresses the range of values to [0, m), and returns m
int compress(vector<int>& vec) {
    vector<int> ord = vec;
    sort(ord.begin(), ord.end());
    ord.erase(unique(ord.begin(), ord.end()), ord.end());
    for (int& v : vec) v = bins(ord, v);
    return ord.size();
}

// Returns length of longest strictly increasing subsequence with at most k exceptions
int lisExc(int k, vector<int> vec) {
    int n = vec.size();
    int m = compress(vec);
    vector<int> dp(n, 0);
    for (int j = 0;; ++j) {
        Fenwick fenw(m+1); // longest subsequence with at most j exceptions ending at this value
        int max_exc = 0; // longest subsequence with at most j-1 exceptions ending before this
        for (int i = 0; i < n; ++i) {
            int off = 1 + max(max_exc, fenw.get(vec[i]));
            max_exc = max(max_exc, dp[i]);

            dp[i] = off;
            fenw.inc(vec[i]+1, off);
        }
        if (j == k) return fenw.get(m);
    }
}

int main() {
    int n, k;
    cin >> n >> k;

    vector<int> vec(n);
    for (int i = 0; i < n; ++i) cin >> vec[i];

    int res = lisExc(k, vec);
    cout << res << '\n';
}

现在我们将回到 O(n log² n) 算法。选择某个整数 0

请注意,如果 r = MINB[a][r'] 且 MAXB[a][r] >= MAXB[a][r'],因此如果我们假设两个声明结果,我们可以对 r 进行二分搜索,尝试 O(log n) 值。因此,如果我们能够在 O(n log n) 时间内计算 DP'、MINB 和 MAXB,那么我们就可以实现复杂度 O(n log² n)。

为此,我们需要一个存储元组 P[i] = (v_i, low_i, high_i) 的线段树,并支持以下操作:

  1. 给定范围 [a, b],找到该范围内的最大值(最大值 v_i,a

  2. 设置元组 P[i] 的值

假设对线段树有一定的了解,这很容易实现,每个操作的复杂度为 O(log n) 时间。具体可以参考下面算法的实现。

现在我们将展示如何在 O(n log n) 中计算 DP'、MINB 和 MAXB。修复 r。构建最初包含 n+1 个空值(-INF、INF、-INF)的线段树。当 j 小于当前位置 i 时,我们认为 P[V[j]] = (DP'[j], MINB[j], MAXB[j])。如果 r > 0,则设置 DP'[0] = 0、MINB[0] = 0 且 MAXB[0] 为 0,否则设置为 INF 且 P[0] = (DP'[0], MINB[0], MAXB[ 0])。

从 1 到 n 循环 i。以 i 结尾的子序列有两种类型:前一个元素大于 V[i] 的子序列和小于 V[i] 的子序列。为了考虑第二种,查询 [0, V[i]] 范围内的线段树。令结果为 (v_1, low_1, high_1)。设置 off1 = (v_1 + 1, low_1, high_1)。对于第一种,查询[V[i], n]范围内的线段树。令结果为 (v_2, low_2, high_2)。设置 off2 = (v_2 + 1 - r, low_2 + 1, high_2 + 1),其中我们会因创建异常而受到 r 的惩罚。

然后我们将off1和off2组合成off。如果 off1.v > off2.v 设置 off = off1,如果 off2.v > off1.v 设置 off = off2。否则,设置 off = (off1.v, min(off1.low, off2.low), max(off1.high, off2.high))。然后设置 DP'[i] = off.v、MINB[i] = off.low、MAXB[i] = off.high 和 P[i] = off。

由于我们在每个 i 处进行两次线段树查询,因此总共需要 O(n log n) 时间。通过归纳很容易证明我们计算出正确的值 DP'、MINB 和 MAXB。

简而言之,算法是:

  1. 预处理,修改值,使它们形成排列,最后的值是最大值。

  2. 二分查找正确的 r,初始边界 0

  3. 用空值初始化线段树,设置DP'[0]、MINB[0]和MAXB[0]。

  4. 从 i = 1 循环到 n,在步骤 i

    • 查询线段树的范围[0, V[i]]和[V[i], n],
    • 基于这些查询计算 DP'[i]、MINB[i] 和 MAXB[i],以及
    • 将线段树中位置 V[i] 的值设置为元组 (DP'[i], MINB[i], MAXB[i])。
  5. 如果 MINB[n][r]

  6. 否则,如果 MAXB[n][r] k,则正确的 r 大于当前的 r。更新 r 的边界并返回到步骤 1。

这是该算法的 C++ 实现。它还找到最佳子序列。

    #include <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;
    using ll = long long;
    const int INF = 2 * (int)1e9;

    pair<ll, pair<int, int>> combine(pair<ll, pair<int, int>> le, pair<ll, pair<int, int>> ri) {
        if (le.first < ri.first) swap(le, ri);
        if (ri.first == le.first) {
            le.second.first = min(le.second.first, ri.second.first);
            le.second.second = max(le.second.second, ri.second.second);
        }
        return le;
    }

    // Specialised range maximum segment tree
    class SegTree {
        private:
            vector<pair<ll, pair<int, int>>> seg;
            int h = 1;

            pair<ll, pair<int, int>> recGet(int a, int b, int i, int le, int ri) const {
                if (ri <= a || b <= le) return {-INF, {INF, -INF}};
                else if (a <= le && ri <= b) return seg[i];
                else return combine(recGet(a, b, 2*i, le, (le+ri)/2), recGet(a, b, 2*i+1, (le+ri)/2, ri));
            }
        public:
            SegTree(int n) {
                while(h < n) h *= 2;
                seg.resize(2*h, {-INF, {INF, -INF}});
            }
            void set(int i, pair<ll, pair<int, int>> off) {
                seg[i+h] = combine(seg[i+h], off);
                for (i += h; i > 1; i /= 2) seg[i/2] = combine(seg[i], seg[i^1]);
            }
            pair<ll, pair<int, int>> get(int a, int b) const {
                return recGet(a, b+1, 1, 0, h);
            }
    };

    // Binary searches index of v from sorted vector
    int bins(const vector<int>& vec, int v) {
        int low = 0;
        int high = (int)vec.size() - 1;
        while(low != high) {
            int mid = (low + high) / 2;
            if (vec[mid] < v) low = mid + 1;
            else high = mid;
        }
        return low;
    }

    // Finds longest strictly increasing subsequence with at most k exceptions in O(n log^2 n)
    vector<int> lisExc(int k, vector<int> vec) {
        // Compress values
        vector<int> ord = vec;
        sort(ord.begin(), ord.end());
        ord.erase(unique(ord.begin(), ord.end()), ord.end());
        for (auto& v : vec) v = bins(ord, v) + 1;

        // Binary search lambda
        int n = vec.size();
        int m = ord.size() + 1;
        int lambda_0 = 0;
        int lambda_1 = n;
        while(true) {
            int lambda = (lambda_0 + lambda_1) / 2;
            SegTree seg(m);
            if (lambda > 0) seg.set(0, {0, {0, 0}});
            else seg.set(0, {0, {0, INF}});

            // Calculate DP
            vector<pair<ll, pair<int, int>>> dp(n);
            for (int i = 0; i < n; ++i) {
                auto off0 = seg.get(0, vec[i]-1); // previous < this
                off0.first += 1;

                auto off1 = seg.get(vec[i], m-1); // previous >= this
                off1.first += 1 - lambda;
                off1.second.first += 1;
                off1.second.second += 1;

                dp[i] = combine(off0, off1);
                seg.set(vec[i], dp[i]);
            }

            // Is min_b <= k <= max_b?
            auto off = seg.get(0, m-1);
            if (off.second.second < k) {
                lambda_1 = lambda - 1;
            } else if (off.second.first > k) {
                lambda_0 = lambda + 1;
            } else {
                // Construct solution
                ll r = off.first + 1;
                int v = m;
                int b = k;
                vector<int> res;
                for (int i = n-1; i >= 0; --i) {
                    if (vec[i] < v) {
                        if (r == dp[i].first + 1 && dp[i].second.first <= b && b <= dp[i].second.second) {
                            res.push_back(i);
                            r -= 1;
                            v = vec[i];
                        }
                    } else {
                        if (r == dp[i].first + 1 - lambda && dp[i].second.first <= b-1 && b-1 <= dp[i].second.second) {
                            res.push_back(i);
                            r -= 1 - lambda;
                            v = vec[i];
                            --b;
                        }
                    }
                }
                reverse(res.begin(), res.end());
                return res;
            }
        }
    }

    int main() {
        int n, k;
        cin >> n >> k;

        vector<int> vec(n);
        for (int i = 0; i < n; ++i) cin >> vec[i];

        vector<int> ans = lisExc(k, vec);
        for (auto i : ans) cout << i+1 << ' ';
        cout << '\n';
    }

我们现在将证明这两个说法。我们希望证明

  1. DP'[a][r] = DP[a][b] - rb 当且仅当 MINB[a][r]

  2. 对于所有 a, k,存在一个整数 r,0

这两点都是从问题的凹性出发的。凹性意味着对于所有 a、k,DP[a][k+2] - DP[a][k+1]

修复 a 和 r。设 f(b) = DP[a][b] - rb,且​​ d(b) = f(b+1) - f(b)。从问题的凹性来看,我们有 d(k+1) = f(i)。因此 d(x)

为了证明第二个,设置 r = DP[a][k+1] - DP[a][k] 并如前所述定义 f、d。那么 d(k) = 0,因此 d(i) >= 0(对于 i k),因此 f(k) 是所需的最大值。

证明凹性更加困难。有关证明,请参阅我的答案 https://cs.stackexchange.com/questions/118858/how-can-ideas-like-lagrange-multipliers-and-penalty-method-be-applied-for-solvin/118859#118859在 cs.stackexchange。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

最长 K 顺序递增子序列 的相关文章

  • 获取嵌套数组 JS 中对象的所有父对象

    我在使用 vuejs 的项目上遇到问题 我有一个像这样的嵌套对象数组 Data data id 1 parent id null title First folder children id 3 parent id 1 title Firs
  • 查找所有数组的长度多维数组,Java

    我想使用多维数组来存储数据网格 但是 我还没有找到一种简单的方法来查找长度2nd数组的一部分 例如 boolean array new boolean 3 5 System out println array length 只会输出3 是否
  • 是否有一种算法可以在线性时间内计算数组反转?

    我知道有多少倒转 en wikipedia org wiki Inversion 28discrete mathematics 29 in an n 元素数组可以在 O n log n 操作使用增强型归并排序 http www geeksf
  • 什么是“朴素”算法,什么是“封闭式”解决方案?

    我有一些关于描述算法时使用的术语语义的问题 首先 朴素 算法是什么意思 这与给定问题的其他解决方案有何不同 解决方案还可以采取哪些其他形式 其次 我听到很多人提到 封闭式 解决方案 我也不知道这意味着什么 但在尝试解决递归关系时经常会出现
  • 如何求两个地点的经纬度距离?

    我有一组位置的纬度和经度 怎么找distance从集合中的一个位置到另一个位置 有公式吗 半正矢公式假定地球是球形的 然而 地球的形状更为复杂 扁球体模型会给出更好的结果 如果需要这样的精度 你应该更好地使用文森特逆公式 See http
  • 使用 javascript Array reduce() 方法有什么真正的好处吗?

    reduce 方法的大多数用例都可以使用 for 循环轻松重写 对 JSPerf 的测试表明 reduce 通常会慢 60 75 具体取决于每次迭代内执行的操作 除了能够以 函数式风格 编写代码之外 还有什么真正的理由使用reduce 吗
  • 如何在 Microsoft 报告中显示字节数组中的图像

    我使用报表文件和 ReportViewer 控件来显示在运行时从对象动态加载数据的报表 我需要显示一个以字节数组形式存储在对象中的图像 PictureBox 的值当前设置为 First Fields ImageData Value dtst
  • 如何在C中实现带连分数的自然对数?

    这里我有一个小问题 根据这个公式创建一些东西 这就是我所拥有的 但它不起作用 弗兰基 我真的不明白它应该如何工作 我尝试用一 些错误的指令对其进行编码 N 是迭代次数和分数部分 我认为它会以某种方式导致递归 但不知道如何 谢谢你的帮助 do
  • 这个函数(for循环)空间复杂度是O(1)还是O(n)?

    public void check 10 for string i list Integer a hashtable get i if a gt 10 hashtable remove i 这是 O 1 还是 O n 我猜测 O n 但不是
  • 传递给函数时多维数组的指针类型是什么? [复制]

    这个问题在这里已经有答案了 我在大学课堂上学习了 C 语言和指针 除了多维数组和指针之间的相似性之外 我认为我已经很好地掌握了这个概念 我认为由于所有数组 甚至多维 都存储在连续内存中 因此您可以安全地将其转换为int 假设给定的数组是in
  • 贝尔曼福特算法可以有任意的边顺序吗?

    我刚刚开始学习新算法 但当我阅读 极客为极客而写的贝尔曼福特算法 时 我陷入了困境 http www geeksforgeeks org dynamic programming set 23 bellman ford algorithm h
  • Javascript 在数组索引上传播以将新项目“推送”到嵌套数组

    考虑以下数据 let data foo true bar 1 2 3 foo true bar 8 9 我试图push嵌套的东西bar索引上的数组1使用扩展语法 https developer mozilla org en US docs
  • “实际或正式的参数列表长度不同”

    当我尝试将某些内容放入 括号中时Friends f new Friends friendsName friendsAge 它出现错误 Friends 类中的构造函数 Friends 不能应用于给定类型 必需 无参数 发现 字符串 整数 原因
  • $0 和 $1 在 Swift 闭包中意味着什么?

    let sortedNumbers numbers sort 0 gt 1 print sortedNumbers 谁能解释一下什么 0 and 1在斯威夫特中意味着什么 另一个样本 array forEach actions append
  • 颜色逻辑算法

    我们正在构建一个体育应用程序 并希望将团队颜色融入到应用程序的各个部分 现在 每个团队都可以使用几种不同的颜色来表示 我想做的是执行检查以验证两个团队颜色是否在彼此一定的范围内 这样我就不会显示两个相似的颜色 因此 如果团队 1 的主要团队
  • 使用什么算法来确定使系统达到“零”状态所需的最小操作数?

    这是一种更通用的问题 不是特定于语言的 有关要使用的想法和算法的更多信息 系统如下 它登记朋友群体之间的小额贷款 Alice and Bill要去吃午饭 比尔的卡坏了 所以爱丽丝支付了他的餐费 10 美元 第二天Bill and Charl
  • 删除近排序数组中未排序/离群元素

    给定一个像这样的数组 15 14 12 3 10 4 2 1 我如何确定哪些元素乱序并删除它们 在本例中为数字 3 我不想对列表进行排序 而是检测异常值并将其删除 另一个例子 13 12 4 9 8 6 7 3 2 我希望能够删除 4 和
  • 从 Laravel 4 输入生成新数组

    我使用 Input all 从动态生成的表单中获取一些输入 我使用 jQuery 来允许用户添加字段 字段名称为 first names last names 和 emails input 变量现在看起来像这样 array size 4 t
  • 如何从 appsettings.json 文件中的对象数组读取值

    我的 appsettings json 文件 StudentBirthdays Anne 01 11 2000 Peter 29 07 2001 Jane 15 10 2001 John Not Mentioned 我有一个单独的配置类 p
  • 无法理解Peterson算法的正确性

    我在这里讨论彼得森算法的一个场景 flag 0 0 flag 1 0 turn P0 flag 0 1 turn 1 while flag 1 1 turn 1 busy wait

随机推荐

  • 从 Django 缓存中删除特定项目?

    我正在使用站点范围的缓存内存缓存 http en wikipedia org wiki Memcached作为后端 当底层数据库对象更改时 我想使缓存中的页面无效 如果页面名称发生更改 那么我将使整个缓存无效 因为它会影响每个页面上的导航
  • 更改 iis 7 的 Inet 根文件夹

    我面临着一个非常令人恼火的挑战 我必须在生产服务器中部署 ASP NET MVC 3 应用程序 在这个生产服务器中我有两个驱动器C and D 我有权将我的网站放在D 数据文件夹我不能使用C 不幸的是 IIS 创建了Inet目录在C 显然
  • 如何使用 Android 模拟器查找 GPS 位置?

    你好 朋友们 我正在尝试查找 Android 模拟器的当前 GPS 位置 我已经使用了命令 geo fix 但是如果我尝试检索当前位置 它会显示异常 任何人都可以帮助我吗 从模拟器中您无法获取当前位置 你必须自己定位位置 试试这个 C an
  • 带有子列表的通用记录 TList?

    我想在 Delphi XE5 中使用带有子列表的通用记录 TList type TMyRecord record Value1 Real SubList TList
  • .htaccess 重定向 – 两个重定向之间的差异

    您能解释一下下面两个 htaccess 重定向之间的区别吗 第一个重定向是我最常使用的重定向 但它在最近的网站上不起作用 太多重定向 即使我没有任何设置 但第二个重定向有效 我很好奇 RewriteEngine On RewriteCond
  • 添加到 ArrayList 时出现 Java NullPointerException?

    我的代码抛出 NullPointerException 即使该对象似乎正确存在 public class IrregularPolygon private ArrayList
  • 使用 bash 脚本在 Info.plist 中添加/替换 URL 方案

    我想添加 替换 URL 方案Info plist使用 bash 脚本 命令创建文件 我尝试过sed命令有各种模式但没有成功 我们希望使用 Jenkins 自动生成构建 并且我们的 URL 方案可以针对各种构建进行更改 因此我们想要修改Inf
  • CMYK 2 RGB 问题

    我在将 CMYK 颜色转换为 RGB 时遇到问题 在互联网上有很多公式可以转换它 但例如当我将 CMYK 0 100 100 0 转换为 RGB 时 它得到的值是 255 0 0 但在 Adob e Photoshop 中 RGB 值是 2
  • 将列表组合成元组对 (x, y)

    我正在尝试组合通过传入的数字对sys argv 例子 python myscript py 35 12323 112 76767 36 33345 112 76890 33 68689 111 8980 我的目标是将它们变成元组中的两个集合
  • 使用 PInvoke 从 C# 读取具有“union”类型的 C 结构

    我正在尝试将用 C 构建的结构引入托管端 C 让我们假设这个结构 C 代码 typedef struct S int i union TypeA a TypeB b TypeC c uni S 现在 我创建 C 包装类 StructLayo
  • 查询 Firestore 中的特定日期

    我正在尝试查询 Firestore 中的指定日期 到目前为止我已经尝试过这段代码 let ref db collection schools doc DglhflywuybkOuCq7tGW let start new Date 2018
  • 如何在scala的specs2测试中使用jUnit的TemporaryFolder?

    我正在使用 Playframework 编写测试 我需要创建一个临时文件 RunWith classOf JUnitRunner class DiagnosticSpec extends Specification Rule val tem
  • 双前向/后向管道操作符是否有记录?

    我记得读过有关双管道运算符的内容 gt 和 Example let print a b sprintf O O a b 1 2 gt print val it string 1 2 双 向前 向后 管道运算符记录在以下列表中MSDN 上的
  • 操作内存中具有多个空字符的 C 字符串

    我需要在一块内存中搜索一串字符 但其中几个字符串的每个字符都为空分隔 如下所示 我 a m a s t r i n g 所有 都是空字符 我的问题来自于实际将其记入内存 我尝试过多种方法 例如 char str2 str2 char mal
  • 如何覆盖 app/code/core/Mage/Core/functions.php 中的 Magento 函数

    我需要重写此文件中的一个函数 应用程序 代码 核心 Mage Core functions php 问题是 它是如此核心 以至于没有与之关联的类 可能是因为 Core 甚至不是一个模块 有谁知道如何在没有类的情况下覆盖文件中的函数 任何帮助
  • 保护 AWS API 网关的安全

    我们有一个现有的应用程序 并且正在开发 AWS 中的应用程序所需的新 API 我们希望对 AWS API 启用基于角色的访问控制 而无需将用户迁移到 AWS Cognito 我们认为我们可能需要使用开发人员身份提供商和 IAM 角色 但不确
  • NFC 中的 AAR 记录:有效负载在哪里?

    根据这个答案 https stackoverflow com a 9235624 115145经测试验证 当您使用 Android Beam 推送包含 AAR 记录的 NFC 消息时 接收设备将启动MAIN LAUNCHERAAR 中指定的
  • Snakemake 声明规则以非零退出代码退出,即使使用“|| true”?

    我的 Snakemake 管道断言 每当我运行任何规则时 我的代码都会引发非零退出代码 即使我的代码在我手动运行相同的代码时返回错误代码 0 并且在 Snakemake 中运行时它可以正常工作 根据建议这个问题 https stackove
  • 如何在Linux shell脚本中将文本文件中的两行合并到同一行中

    我使用 wget 命令从 Nagios 下载了它的 html 文件 然后使用以下代码将该 html 文件转换为 Textfile html2text width 180 file html gt a txt 然后我剪切了前 10 行 因为我
  • 最长 K 顺序递增子序列

    为什么我创建了一个重复的线程 阅读后我创建了这个线程允许有 K 个例外的最长递增子序列 https stackoverflow com questions 56155854 longest increasing subsequence wi