Giter Club home page Giter Club logo

Comments (4)

xiongcaihu avatar xiongcaihu commented on May 5, 2024 1
/**
 * @param {string[]} strs
 * @param {number} m
 * @param {number} n
 * @return {number}
 * F(i,C) = max(F(i-1,C),F(i-1,C-w)+v); 0,1背包公式
 * 
 * 多维版
 * F(i,m,n) = max(F(i-1,m,n),F(i-1,m-j,n-k)+1); j=当前字符串的0数量,k为1的数量
 * 
 * 每遍历到strs的一个位置时,有两种选择,选择当前字符串,或者不选择
 * 如果选择,那么当前F(i,m,n)的最优结果等于减去这个字符串占用的01数量后的最优结果,即F(i-1,m-j,n-k)+1
 * 如果不选择,那么当前F(i,m,n)的最优结果等于遍历到上一个字符串时的结果,即F(i-1,m,n)
 * 
 */
var findMaxForm = function (strs, m, n) {
    if (strs.length == 0) return 0;
    var dp = Array.from({
        length: m + 1
    }, () => new Array(n + 1).fill(0));
    for (var i = 0; i < strs.length; i++) {
        var count1 = 0,
            count0 = 0;
        for (var item of strs[i]) {
            if (item == '1') count1++;
            else count0++;
        }

        for (var k = m; k >= count0; k--) {
            for (var j = n; j >= count1; j--) {
                dp[k][j] = Math.max(dp[k][j], dp[k - count0][j - count1] + 1);
            }
        }
    }

    return dp[m][n];
};

from leetcode.

EdgeAsh avatar EdgeAsh commented on May 5, 2024

认领

from leetcode.

snowan avatar snowan commented on May 5, 2024

我试试english version?

from leetcode.

azl397985856 avatar azl397985856 commented on May 5, 2024

我试试english version?

好的

from leetcode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.