mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-29 03:17:13 +00:00
build
This commit is contained in:
@@ -166,7 +166,7 @@ comments: true
|
||||
}
|
||||
|
||||
/* 分数背包:贪心 */
|
||||
double fractionalKnapsack(int[] wgt, int[] val, int cap) {
|
||||
double FractionalKnapsack(int[] wgt, int[] val, int cap) {
|
||||
// 创建物品列表,包含两个属性:重量、价值
|
||||
Item[] items = new Item[wgt.Length];
|
||||
for (int i = 0; i < wgt.Length; i++) {
|
||||
|
||||
@@ -95,7 +95,7 @@ comments: true
|
||||
|
||||
```csharp title="coin_change_greedy.cs"
|
||||
/* 零钱兑换:贪心 */
|
||||
int coinChangeGreedy(int[] coins, int amt) {
|
||||
int CoinChangeGreedy(int[] coins, int amt) {
|
||||
// 假设 coins 列表有序
|
||||
int i = coins.Length - 1;
|
||||
int count = 0;
|
||||
|
||||
@@ -168,7 +168,7 @@ $$
|
||||
|
||||
```csharp title="max_capacity.cs"
|
||||
/* 最大容量:贪心 */
|
||||
int maxCapacity(int[] ht) {
|
||||
int MaxCapacity(int[] ht) {
|
||||
// 初始化 i, j 分列数组两端
|
||||
int i = 0, j = ht.Length - 1;
|
||||
// 初始最大容量为 0
|
||||
|
||||
@@ -147,7 +147,7 @@ $$
|
||||
|
||||
```csharp title="max_product_cutting.cs"
|
||||
/* 最大切分乘积:贪心 */
|
||||
int maxProductCutting(int n) {
|
||||
int MaxProductCutting(int n) {
|
||||
// 当 n <= 3 时,必须切分出一个 1
|
||||
if (n <= 3) {
|
||||
return 1 * (n - 1);
|
||||
|
||||
Reference in New Issue
Block a user