Capacitated Facility Location Problem

本次算法项目中,我们被要求解决一个“仓库选址问题”。在该问题中,我们被给定了一定数量的顾客和一定数量的仓库。每个顾客到不同的仓库有不同的服务成本,同时每个仓库也有最小的经营成本(这意味着一旦仓库服务了顾客,其就会产生一个额外的成本)。我们的目标是寻找到一个顾客分配方案,使得总的服务成本(包含经营成本)最少。

FLP 是一个经典的 NP 难问题,CFLP 也一样。由于 NP 难问题夸张的求解时间复杂度,我们不能够寻求一个常规的,最优的方案来求解。相对的,我们只能够构建一个能够收敛到近似全局最优的启发式算法来获得一个近似解。

在本次项目中,我们选择了 爬山算法(Hill Climbing Algorithm))遗传算法(Genetic Algorithm) 作为我们的代码实现,并通过对比来寻求二者间的差异。

代码仓库

Leetcode 526. Beautiful Arrangement

题目

526. Beautiful Arrangement

  • Difficulty: Middle
  • Total Accepted: 31,338
  • Total Submissions: 59,005

Leetcode 945. Minimum Increment to Make Array Unique

题目

945. Minimum Increment to Make Array Unique

  • Difficulty: Middle
  • Total Accepted: 5,139
  • Total Submissions: 12,879

Leetcode 948. Bag of Tokens

题目

948. Bag of Tokens

  • Difficulty: Middle
  • Total Accepted: 3,132
  • Total Submissions: 8,230

Leetcode 188. Best Time to Buy and Sell Stock

本题有四个不同难度的版本:

下面分题进行讲解:

121. Best Time to Buy and Sell Stock

  • Difficulty: Easy
  • Total Accepted: 379.2K
  • Total Submissions: 843.6K

Say you have an array for which the ith element is the price of a given stock on day i.

If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.

Note that you cannot sell a stock before you buy one.

Leetcode 140. Word Break

题目

本题有两个不同难度的版本:139. Word Break 和 140. Word Break II。

139. Word Break

  • Difficulty: Medium
  • Total Accepted: 263K
  • Total Submissions: 798K

Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.

Note:

The same word in the dictionary may be reused multiple times in the segmentation.
You may assume the dictionary does not contain duplicate words.

Example 1:

Input: s = "leetcode", wordDict = ["leet", "code"]
Output: true
Explanation: Return true because "leetcode" can be segmented as "leet code".

Example 2:

Input: s = "applepenapple", wordDict = ["apple", "pen"]
Output: true
Explanation: Return true because "applepenapple" can be segmented as "apple pen apple".
             Note that you are allowed to reuse a dictionary word.

Example 3:

Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]
Output: false

Leetcode 32. Longest Valid Parentheses

题目

32. Longest Valid Parentheses

  • Difficulty: Hard
  • Total Accepted: 152.4K
  • Total Submissions: 632.8K

Leetcode 135. Candy

题目

135. Candy

  • Difficulty: Hard
  • Total Accepted: 87.48K
  • Total Submissions: 330.65K

Leetcode 44. Wildcard Matching

题目

44. Wildcard Matching

  • Difficulty: Hard
  • Total Accepted: 144.11K
  • Total Submissions: 665.07K

Leetcode 65. Valid Number

题目

65. Valid Number

  • Difficulty: Hard
  • Total Accepted: 99.5K
  • Total Submissions: 753.7K
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×