Skip to content

【561-Week-09】毕业总结 #1358

Open

Description

@1yx

模板

递归

void recur(int level, int param) {
    // terminator
    if (level > maxLevel) return;
    // process current logic
    process(level, param);
    param.do();
    // drill down
    recur(level + 1, param);
    // restore current states
    param.undo();
}

分治

void divideConquer(problem) {
    // recursion terminator 
    if (problem.isEmpty()) return;

    // prepare data
    problem.do();
    Element[] subproblem = problem.splite();
    int[] subRes = new int[subproblem.length];
    // conquer subproblem;
    int i = 0;
    for (Element sub : subproblem) {
        subRes[i++] = divideConquer(sub);
    }

    // process and generate result;
    int result = processResult(subRes);
    
    // revert current level states
    problem.undo();
}

动态规划

void dp (int n) {
    int[][] dp = new int[n][n];
    for (int i = 0; i < n; i ++) 
        for (int j = 0; j < n; j ++)
            dp[i][j] = func(dp[_i][_j]);
    return dp[n - 1][n - 1];
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions