2026-06-15 09:00:38 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 算法分析教学平台 - 章节与代码文件数据
|
|
|
|
|
|
* 对应教材章节:基础(复杂度分析)、分治法、动态规划、贪心、回溯、分支限界
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
export const chapters = [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'ch1',
|
2026-06-16 15:13:47 +08:00
|
|
|
|
title: '第一章 算法基础 — 复杂度分析',
|
2026-06-15 09:00:38 +08:00
|
|
|
|
subtitle: '算法时间复杂度与空间复杂度基础',
|
|
|
|
|
|
description: '本章介绍算法分析的基础知识,包括时间复杂度、空间复杂度的概念,以及通过实验比较不同算法的性能差异。',
|
|
|
|
|
|
icon: '📊',
|
|
|
|
|
|
topics: [
|
|
|
|
|
|
'时间复杂度概念(O、Ω、Θ)',
|
|
|
|
|
|
'空间复杂度分析',
|
|
|
|
|
|
'递归算法复杂度',
|
|
|
|
|
|
'实验对比分析方法'
|
|
|
|
|
|
],
|
2026-06-16 15:32:49 +08:00
|
|
|
|
knowledgeGraph: {
|
|
|
|
|
|
nodes: [
|
|
|
|
|
|
{ id: 'algo', label: '算法分析', desc: '评估算法效率的方法论' },
|
|
|
|
|
|
{ id: 'time', label: '时间复杂度', desc: '运行时间随输入规模增长的量级' },
|
|
|
|
|
|
{ id: 'space', label: '空间复杂度', desc: '运行所需的额外存储空间量级' },
|
|
|
|
|
|
{ id: 'bigO', label: '大O记号', desc: '渐近上界 f(n)=O(g(n))' },
|
|
|
|
|
|
{ id: 'bigOmega', label: '大Ω记号', desc: '渐近下界 f(n)=Ω(g(n))' },
|
|
|
|
|
|
{ id: 'bigTheta', label: '大Θ记号', desc: '渐近紧界 f(n)=Θ(g(n))' },
|
|
|
|
|
|
{ id: 'recursive', label: '递归复杂度', desc: '递归算法的时间复杂度分析' },
|
|
|
|
|
|
{ id: 'compare', label: '实验对比', desc: '通过实际运行比较算法性能' },
|
|
|
|
|
|
{ id: 'const', label: 'O(1) 常数阶', desc: '运行时间与 n 无关' },
|
|
|
|
|
|
{ id: 'log', label: 'O(log n) 对数阶', desc: '二分法、倍增法' },
|
|
|
|
|
|
{ id: 'linear', label: 'O(n) 线性阶', desc: '单次遍历' },
|
|
|
|
|
|
{ id: 'nlogn', label: 'O(n log n) 线性对数阶', desc: '分治排序' },
|
|
|
|
|
|
{ id: 'square', label: 'O(n²) 平方阶', desc: '双层循环' },
|
|
|
|
|
|
{ id: 'exp', label: 'O(2ⁿ) 指数阶', desc: '回溯搜索' }
|
|
|
|
|
|
],
|
|
|
|
|
|
edges: [
|
|
|
|
|
|
{ source: 'algo', target: 'time', label: '核心指标' },
|
|
|
|
|
|
{ source: 'algo', target: 'space', label: '核心指标' },
|
|
|
|
|
|
{ source: 'time', target: 'bigO', label: '常用表示' },
|
|
|
|
|
|
{ source: 'time', target: 'bigOmega', label: '常用表示' },
|
|
|
|
|
|
{ source: 'time', target: 'bigTheta', label: '常用表示' },
|
|
|
|
|
|
{ source: 'time', target: 'recursive', label: '特殊情形' },
|
|
|
|
|
|
{ source: 'time', target: 'compare', label: '验证手段' },
|
|
|
|
|
|
{ source: 'bigO', target: 'const', label: '最优' },
|
|
|
|
|
|
{ source: 'bigO', target: 'log', label: '高效' },
|
|
|
|
|
|
{ source: 'bigO', target: 'linear', label: '中等' },
|
|
|
|
|
|
{ source: 'bigO', target: 'nlogn', label: '较慢' },
|
|
|
|
|
|
{ source: 'bigO', target: 'square', label: '慢' },
|
|
|
|
|
|
{ source: 'bigO', target: 'exp', label: '不可行' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
2026-06-16 10:23:48 +08:00
|
|
|
|
subfolders: [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'complexity-demo',
|
|
|
|
|
|
label: '🧪 时间复杂度实验',
|
|
|
|
|
|
demo: { path: '/complexity-demo', label: '📊 动态演示', description: '通过动画直观理解 O(1)、O(log n)、O(n)、O(n log n)、O(n²)、O(2ⁿ) 的增长差异' },
|
|
|
|
|
|
files: []
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'code-examples',
|
|
|
|
|
|
label: '代码示例',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch1/first.c', name: 'first.c', label: '递归打印图案', description: '递归打印矩形/三角形图案,演示递归基本结构', pyPath: 'py/ch1/first.py' },
|
|
|
|
|
|
{ path: 'c/ch1/compare.c', name: 'compare.c', label: '性能对比(累加 vs 高斯公式)', description: '比较循环累加与高斯求和公式的耗时差异,直观感受算法效率', pyPath: 'py/ch1/compare.py' },
|
|
|
|
|
|
{ path: 'c/ch1/compareall.c', name: 'compareall.c', label: '多项性能对比', description: '更多累加与高斯公式的计时对比实验' }
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
2026-06-15 09:00:38 +08:00
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'ch2',
|
|
|
|
|
|
title: '第二章 分治法',
|
|
|
|
|
|
subtitle: 'Divide and Conquer — 分而治之',
|
|
|
|
|
|
description: '分治法将大问题分解为若干规模较小的子问题,递归求解后再合并结果。本章涵盖归并排序、快速排序、二分查找、大整数乘法、矩阵乘法等经典分治算法。',
|
|
|
|
|
|
icon: '🔪',
|
|
|
|
|
|
topics: [
|
|
|
|
|
|
'分治策略基本思想',
|
|
|
|
|
|
'归并排序',
|
|
|
|
|
|
'快速排序(多种划分方式)',
|
|
|
|
|
|
'二分查找(递归与迭代)',
|
|
|
|
|
|
'大整数乘法',
|
|
|
|
|
|
'Strassen矩阵乘法',
|
|
|
|
|
|
'递归求最大值',
|
|
|
|
|
|
'全排列生成'
|
|
|
|
|
|
],
|
2026-06-16 15:32:49 +08:00
|
|
|
|
knowledgeGraph: {
|
|
|
|
|
|
nodes: [
|
|
|
|
|
|
{ id: 'divide', label: '分治策略', desc: '分解→解决→合并' },
|
|
|
|
|
|
{ id: 'split', label: '分解(Divide)', desc: '将大问题拆分为子问题' },
|
|
|
|
|
|
{ id: 'conquer', label: '解决(Conquer)', desc: '递归求解子问题' },
|
|
|
|
|
|
{ id: 'merge', label: '合并(Combine)', desc: '将子问题解合并为原问题解' },
|
|
|
|
|
|
{ id: 'sort', label: '排序问题', desc: '基于比较的排序算法' },
|
|
|
|
|
|
{ id: 'search', label: '查找问题', desc: '在有序数据中搜索' },
|
|
|
|
|
|
{ id: 'math', label: '数学问题', desc: '数值计算中的分治应用' },
|
|
|
|
|
|
{ id: 'mergesort', label: '归并排序', desc: '先递归排序再合并 O(n log n)' },
|
|
|
|
|
|
{ id: 'quicksort', label: '快速排序', desc: '先划分再递归排序 O(n log n)' },
|
|
|
|
|
|
{ id: 'halfsearch', label: '二分查找', desc: '每次缩小一半范围 O(log n)' },
|
|
|
|
|
|
{ id: 'bigint', label: '大整数乘法', desc: '分治降低乘法次数' },
|
|
|
|
|
|
{ id: 'matrix', label: '矩阵乘法', desc: 'Strassen O(n^2.81)' },
|
|
|
|
|
|
{ id: 'recursion', label: '递归技术', desc: '函数自身调用的编程技巧' },
|
|
|
|
|
|
{ id: 'permutation', label: '全排列生成', desc: '递归交换生成所有排列' }
|
|
|
|
|
|
],
|
|
|
|
|
|
edges: [
|
|
|
|
|
|
{ source: 'divide', target: 'split', label: '步骤一' },
|
|
|
|
|
|
{ source: 'divide', target: 'conquer', label: '步骤二' },
|
|
|
|
|
|
{ source: 'divide', target: 'merge', label: '步骤三' },
|
|
|
|
|
|
{ source: 'divide', target: 'sort', label: '典型应用' },
|
|
|
|
|
|
{ source: 'divide', target: 'search', label: '典型应用' },
|
|
|
|
|
|
{ source: 'divide', target: 'math', label: '典型应用' },
|
|
|
|
|
|
{ source: 'divide', target: 'recursion', label: '实现基础' },
|
|
|
|
|
|
{ source: 'sort', target: 'mergesort', label: '稳定排序' },
|
|
|
|
|
|
{ source: 'sort', target: 'quicksort', label: '原地排序' },
|
|
|
|
|
|
{ source: 'search', target: 'halfsearch', label: '有序查找' },
|
|
|
|
|
|
{ source: 'math', target: 'bigint', label: '数值分治' },
|
|
|
|
|
|
{ source: 'math', target: 'matrix', label: '矩阵分治' },
|
|
|
|
|
|
{ source: 'recursion', target: 'permutation', label: '交换法' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
2026-06-15 09:00:38 +08:00
|
|
|
|
subfolders: [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'mergesort',
|
|
|
|
|
|
label: '归并排序',
|
|
|
|
|
|
files: [
|
2026-06-16 09:35:51 +08:00
|
|
|
|
{ path: 'c/ch2/mergesort/guibing.c', name: 'guibing.c', label: '归并排序完整实现', description: '分治归并排序,包含 merge 与 mergeSort 函数', pyPath: 'py/ch2/mergesort/mergesort.py' },
|
2026-06-15 09:00:38 +08:00
|
|
|
|
{ path: 'c/ch2/mergesort/merge.c', name: 'merge.c', label: '归并操作', description: '合并两个有序子数组的核心 merge 操作' }
|
|
|
|
|
|
],
|
|
|
|
|
|
demo: { path: '/sort-demo#merge', label: '🎬 动态演示', description: '观看归并排序的完整动画过程' }
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'quicksort',
|
|
|
|
|
|
label: '快速排序',
|
|
|
|
|
|
files: [
|
2026-06-16 09:35:51 +08:00
|
|
|
|
{ path: 'c/ch2/quicksort/danppt.c', name: 'danppt.c', label: '快速排序(单侧指针)', description: '单侧指针遍历划分的快速排序实现', pyPath: 'py/ch2/quicksort/quicksort.py' },
|
2026-06-15 09:00:38 +08:00
|
|
|
|
{ path: 'c/ch2/quicksort/danleft.c', name: 'danleft.c', label: '快速排序(左指针法)', description: '基于左右指针移动的快速排序变体' },
|
|
|
|
|
|
{ path: 'c/ch2/quicksort/dantwo.c', name: 'dantwo.c', label: '快速排序(双指针法)', description: '另一种双指针快速排序实现' },
|
|
|
|
|
|
{ path: 'c/ch2/quicksort/shuangbian.c', name: 'shuangbian.c', label: '快速排序(双边扫描)', description: '经典的双边扫描分区快速排序' }
|
|
|
|
|
|
],
|
|
|
|
|
|
demo: { path: '/sort-demo#quick', label: '🎬 动态演示', description: '观看快速排序的完整动画过程' }
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'halfsearch',
|
|
|
|
|
|
label: '二分查找',
|
|
|
|
|
|
files: [
|
2026-06-16 09:35:51 +08:00
|
|
|
|
{ path: 'c/ch2/student/halfsearch.c', name: 'halfsearch.c', label: '二分查找(递归版)', description: '递归实现的二分查找算法', pyPath: 'py/ch2/halfsearch/binary_search.py' },
|
2026-06-15 09:00:38 +08:00
|
|
|
|
{ path: 'c/ch2/student/halfsearchnew.c', name: 'halfsearchnew.c', label: '二分查找(迭代版)', description: '迭代实现的二分查找算法' },
|
|
|
|
|
|
{ path: 'c/ch2/halfsearch/fenzhi.c', name: 'fenzhi.c', label: '分治分割示例', description: '二分分治分割示例' },
|
|
|
|
|
|
{ path: 'c/ch2/halfsearch/fenzhirec.c', name: 'fenzhirec.c', label: '递归查找', description: '递归结构的查找实现' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'bigcheng',
|
|
|
|
|
|
label: '大整数乘法',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch2/bigcheng/bigchengold.c', name: 'bigchengold.c', label: '大整数乘法(基础版)', description: '低位进位数组模拟乘法' },
|
|
|
|
|
|
{ path: 'c/ch2/bigcheng/bigchengnew.c', name: 'bigchengnew.c', label: '大整数乘法(分治版)', description: '分治递归的大整数乘法实现' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'matrix',
|
|
|
|
|
|
label: '矩阵乘法',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch2/juzhen/juzhenold.c', name: 'juzhenold.c', label: '矩阵乘法(朴素版)', description: '朴素三层循环矩阵乘法' },
|
|
|
|
|
|
{ path: 'c/ch2/juzhen/juzhennew.c', name: 'juzhennew.c', label: '矩阵乘法(分治版)', description: '分治/Strassen风格的矩阵乘法' },
|
|
|
|
|
|
{ path: 'c/ch2/matrix/macheng.c', name: 'macheng.c', label: '分治矩阵乘法', description: '分块递归矩阵乘法' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'digui',
|
|
|
|
|
|
label: '递归示例',
|
|
|
|
|
|
files: [
|
2026-06-16 09:35:51 +08:00
|
|
|
|
{ path: 'c/ch2/digui/printnumber.c', name: 'printnumber.c', label: '递归打印整数', description: '递归按位打印整数(高位到低位)', pyPath: 'py/ch2/digui/print_number.py' },
|
2026-06-15 09:00:38 +08:00
|
|
|
|
{ path: 'c/ch2/digui/tuxing.c', name: 'tuxing.c', label: '递归图形', description: '递归绘制图形示例' },
|
|
|
|
|
|
{ path: 'c/ch2/shangji/findarrmax.c', name: 'findarrmax.c', label: '递归求最大值', description: '递归查找数组最大值' },
|
|
|
|
|
|
{ path: 'c/ch2/shangji/sanjiao.c', name: 'sanjiao.c', label: '递归三角形', description: '递归打印星号三角形' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'maopao',
|
|
|
|
|
|
label: '冒泡排序',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch2/maopao/mp.c', name: 'mp.c', label: '冒泡排序', description: '冒泡排序实现并打印中间状态' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'allpai',
|
|
|
|
|
|
label: '全排列',
|
|
|
|
|
|
files: [
|
2026-06-16 09:35:51 +08:00
|
|
|
|
{ path: 'c/ch2/ch2.allpai/allpai.c', name: 'allpai.c', label: '全排列生成', description: '递归交换法全排列生成', pyPath: 'py/ch2/allpai/permutations.py' },
|
2026-06-15 09:00:38 +08:00
|
|
|
|
{ path: 'c/ch2/ch2.allpai/allpaichong.c', name: 'allpaichong.c', label: '全排列(去重)', description: '带去重逻辑的全排列生成' },
|
|
|
|
|
|
{ path: 'c/ch2/ch2.allpai/arrpaichong.c', name: 'arrpaichong.c', label: '数组排列去重', description: '数组排列生成与去重' },
|
|
|
|
|
|
{ path: 'c/ch2/student/quanpai.c', name: 'quanpai.c', label: '全排列(学生版)', description: '全排列/排列打印程序' },
|
|
|
|
|
|
{ path: 'c/ch2/student/ppp.c', name: 'ppp.c', label: '全排列(ppp)', description: '递归交换并打印排列' },
|
|
|
|
|
|
{ path: 'c/ch2/student/paichongright.c', name: 'paichongright.c', label: '去重排列', description: '排除重复输出的排列逻辑' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'richeng',
|
|
|
|
|
|
label: '日程表',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch2/richeng/bisan.c', name: 'bisan.c', label: '循环赛日程表', description: '使用2^k分组复制的赛程表逻辑' }
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'ch3',
|
|
|
|
|
|
title: '第三章 动态规划',
|
|
|
|
|
|
subtitle: 'Dynamic Programming — 最优子结构与重叠子问题',
|
|
|
|
|
|
description: '动态规划通过将问题分解为重叠子问题,并利用最优子结构性质,自底向上求解。本章涵盖0/1背包、最长公共子序列(LCS)、矩阵链乘、图像压缩、最少硬币等经典DP问题。',
|
|
|
|
|
|
icon: '🧩',
|
|
|
|
|
|
topics: [
|
|
|
|
|
|
'动态规划基本思想',
|
|
|
|
|
|
'最优子结构与重叠子问题',
|
|
|
|
|
|
'0/1背包问题',
|
|
|
|
|
|
'最长公共子序列(LCS)',
|
|
|
|
|
|
'矩阵链乘',
|
|
|
|
|
|
'图像压缩',
|
|
|
|
|
|
'最少硬币问题',
|
|
|
|
|
|
'杨辉三角'
|
|
|
|
|
|
],
|
2026-06-16 15:32:49 +08:00
|
|
|
|
knowledgeGraph: {
|
|
|
|
|
|
nodes: [
|
|
|
|
|
|
{ id: 'dp', label: '动态规划', desc: '最优子结构 + 重叠子问题' },
|
|
|
|
|
|
{ id: 'substructure', label: '最优子结构', desc: '问题最优解包含子问题最优解' },
|
|
|
|
|
|
{ id: 'overlap', label: '重叠子问题', desc: '子问题被反复求解' },
|
|
|
|
|
|
{ id: 'bottomup', label: '自底向上', desc: '从最小子问题开始逐步求解' },
|
|
|
|
|
|
{ id: 'memo', label: '记忆化搜索', desc: '自顶向下 + 查表' },
|
|
|
|
|
|
{ id: 'table', label: 'DP表/状态转移', desc: '用表格记录子问题解' },
|
|
|
|
|
|
{ id: 'knapsack', label: '0/1背包问题', desc: '选或不选,容量限制下价值最大' },
|
|
|
|
|
|
{ id: 'lcs', label: '最长公共子序列', desc: '两序列的最长公共子序列' },
|
|
|
|
|
|
{ id: 'matrixchain', label: '矩阵链乘', desc: '最优括号化方案' },
|
|
|
|
|
|
{ id: 'image', label: '图像压缩', desc: '最优像素段划分' },
|
|
|
|
|
|
{ id: 'coin', label: '最少硬币', desc: '最少硬币凑出目标金额' }
|
|
|
|
|
|
],
|
|
|
|
|
|
edges: [
|
|
|
|
|
|
{ source: 'dp', target: 'substructure', label: '性质一' },
|
|
|
|
|
|
{ source: 'dp', target: 'overlap', label: '性质二' },
|
|
|
|
|
|
{ source: 'dp', target: 'bottomup', label: '实现方式' },
|
|
|
|
|
|
{ source: 'dp', target: 'memo', label: '实现方式' },
|
|
|
|
|
|
{ source: 'bottomup', target: 'table', label: '核心手段' },
|
|
|
|
|
|
{ source: 'memo', target: 'table', label: '核心手段' },
|
|
|
|
|
|
{ source: 'dp', target: 'knapsack', label: '经典问题' },
|
|
|
|
|
|
{ source: 'dp', target: 'lcs', label: '经典问题' },
|
|
|
|
|
|
{ source: 'dp', target: 'matrixchain', label: '经典问题' },
|
|
|
|
|
|
{ source: 'dp', target: 'image', label: '经典问题' },
|
|
|
|
|
|
{ source: 'dp', target: 'coin', label: '经典问题' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
2026-06-15 09:00:38 +08:00
|
|
|
|
subfolders: [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'bag01',
|
|
|
|
|
|
label: '0/1背包问题',
|
|
|
|
|
|
files: [
|
2026-06-16 09:35:51 +08:00
|
|
|
|
{ path: 'c/ch3/bag01/bag01.c', name: 'bag01.c', label: '0/1背包 DP 实现', description: '经典二维DP矩阵解法', pyPath: 'py/ch3/bag01/knapsack01.py' },
|
2026-06-15 09:00:38 +08:00
|
|
|
|
{ path: 'c/ch3/bag01/bagbag.c', name: 'bagbag.c', label: '背包状态追踪', description: '多种背包实现/状态追踪' },
|
|
|
|
|
|
{ path: 'c/ch3/bag01/bagevery.c', name: 'bagevery.c', label: '背包枚举', description: '背包问题枚举/遍历示例' },
|
|
|
|
|
|
{ path: 'c/ch3/bag01/yanghui.c', name: 'yanghui.c', label: '杨辉三角(二维数组)', description: '使用二维数组打印杨辉三角' },
|
|
|
|
|
|
{ path: 'c/ch3/bag01/yanghuiarr.c', name: 'yanghuiarr.c', label: '杨辉三角(动态分配)', description: '用malloc动态分配版杨辉三角' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'lcs',
|
|
|
|
|
|
label: '最长公共子序列(LCS)',
|
|
|
|
|
|
files: [
|
2026-06-16 09:35:51 +08:00
|
|
|
|
{ path: 'c/ch3/lcs/lcs1.c', name: 'lcs1.c', label: 'LCS 实现(一)', description: '构建LCS DP表', pyPath: 'py/ch3/lcs/lcs.py' },
|
2026-06-15 09:00:38 +08:00
|
|
|
|
{ path: 'c/ch3/lcs/lcs2.c', name: 'lcs2.c', label: 'LCS 实现(二)', description: 'LCS动态规划实现,返回长度' },
|
|
|
|
|
|
{ path: 'c/ch3/lcs/printtable.c', name: 'printtable.c', label: 'LCS 路径回溯', description: '打印LCS路径表并回溯输出LCS' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'matrix',
|
|
|
|
|
|
label: '矩阵算法',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch3/matrix/chengJia.c', name: 'chengJia.c', label: '矩阵乘法', description: '朴素矩阵乘法示例' },
|
|
|
|
|
|
{ path: 'c/ch3/matrix/matrixmul.c', name: 'matrixmul.c', label: '矩阵乘法(标准)', description: '标准矩阵乘法实现' },
|
|
|
|
|
|
{ path: 'c/ch3/matrix/duijiaoxian.c', name: 'duijiaoxian.c', label: '对角线处理', description: '矩阵对角线特性打印' },
|
|
|
|
|
|
{ path: 'c/ch3/matrix/kuohao.c', name: 'kuohao.c', label: '矩阵括号链乘', description: '矩阵链乘括号化DP实现' },
|
|
|
|
|
|
{ path: 'c/ch3/matrix/weishu.c', name: 'weishu.c', label: '位数计算', description: '数字位数/二进制位宽计算' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'image',
|
|
|
|
|
|
label: '图像压缩',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch3/image/imgcompress.c', name: 'imgcompress.c', label: '图像压缩算法', description: '图像压缩段划分与最优分段' },
|
|
|
|
|
|
{ path: 'c/ch3/image/imgcompress0.c', name: 'imgcompress0.c', label: '图像压缩(基础版)', description: '图像压缩段编码示例' },
|
|
|
|
|
|
{ path: 'c/ch3/image/get2Len.c', name: 'get2Len.c', label: '位长计算', description: '计算二进制位长等辅助函数' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'homework',
|
|
|
|
|
|
label: '课后练习',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch3/homework/lesscoin.c', name: 'lesscoin.c', label: '最少硬币问题', description: '典型背包/零钱兑换DP实现' }
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'ch4',
|
|
|
|
|
|
title: '第四章 贪心算法',
|
|
|
|
|
|
subtitle: 'Greedy Algorithm — 局部最优与全局最优',
|
|
|
|
|
|
description: '贪心算法在每一步选择中都采取当前最优的选择,希望最终得到全局最优解。本章涵盖活动选择、Huffman编码、背包问题(贪心版)、最优装载、最短路径、找零问题等。',
|
|
|
|
|
|
icon: '🎯',
|
|
|
|
|
|
topics: [
|
|
|
|
|
|
'贪心策略基本思想',
|
|
|
|
|
|
'活动选择问题',
|
|
|
|
|
|
'Huffman编码',
|
|
|
|
|
|
'贪心背包(部分背包)',
|
|
|
|
|
|
'最优装载问题',
|
|
|
|
|
|
'最短路径',
|
|
|
|
|
|
'找零问题'
|
|
|
|
|
|
],
|
2026-06-16 15:32:49 +08:00
|
|
|
|
knowledgeGraph: {
|
|
|
|
|
|
nodes: [
|
|
|
|
|
|
{ id: 'greedy', label: '贪心策略', desc: '每步选当前最优' },
|
|
|
|
|
|
{ id: 'local', label: '局部最优选择', desc: '当前看来最好的选择' },
|
|
|
|
|
|
{ id: 'global', label: '全局最优解', desc: '贪心选择性质保证' },
|
|
|
|
|
|
{ id: 'optstruct', label: '最优子结构', desc: '子问题最优推导全局最优' },
|
|
|
|
|
|
{ id: 'activity', label: '活动选择', desc: '选择最多不重叠活动' },
|
|
|
|
|
|
{ id: 'huffman', label: 'Huffman编码', desc: '最优前缀码实现数据压缩' },
|
|
|
|
|
|
{ id: 'fbag', label: '贪心背包', desc: '部分背包按单位价值贪心' },
|
|
|
|
|
|
{ id: 'loading', label: '最优装载', desc: '重量限制下装最多的物品' },
|
|
|
|
|
|
{ id: 'path', label: '最短路径', desc: 'Dijkstra:按距离贪心' },
|
|
|
|
|
|
{ id: 'change', label: '找零问题', desc: '按面额从大到小贪心' }
|
|
|
|
|
|
],
|
|
|
|
|
|
edges: [
|
|
|
|
|
|
{ source: 'greedy', target: 'local', label: '核心' },
|
|
|
|
|
|
{ source: 'greedy', target: 'optstruct', label: '前提' },
|
|
|
|
|
|
{ source: 'local', target: 'global', label: '最终目标' },
|
|
|
|
|
|
{ source: 'greedy', target: 'activity', label: '经典应用' },
|
|
|
|
|
|
{ source: 'greedy', target: 'huffman', label: '经典应用' },
|
|
|
|
|
|
{ source: 'greedy', target: 'fbag', label: '经典应用' },
|
|
|
|
|
|
{ source: 'greedy', target: 'loading', label: '经典应用' },
|
|
|
|
|
|
{ source: 'greedy', target: 'path', label: '经典应用' },
|
|
|
|
|
|
{ source: 'greedy', target: 'change', label: '经典应用' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
2026-06-15 09:00:38 +08:00
|
|
|
|
subfolders: [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'huodong',
|
|
|
|
|
|
label: '活动选择',
|
|
|
|
|
|
files: [
|
2026-06-16 09:35:51 +08:00
|
|
|
|
{ path: 'c/ch4/huodong/fenpei.c', name: 'fenpei.c', label: '活动分配', description: '活动选择问题的贪心实现', pyPath: 'py/ch4/huodong/activity_selection.py' }
|
2026-06-15 09:00:38 +08:00
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'huffman',
|
|
|
|
|
|
label: 'Huffman编码',
|
|
|
|
|
|
files: [
|
2026-06-16 09:35:51 +08:00
|
|
|
|
{ path: 'c/ch4/huffman/halfall.c', name: 'halfall.c', label: 'Huffman编码主流程', description: '构建Huffman树并生成编码', pyPath: 'py/ch4/huffman/huffman.py' },
|
2026-06-15 09:00:38 +08:00
|
|
|
|
{ path: 'c/ch4/huffman/halfcode.c', name: 'halfcode.c', label: 'Huffman编码生成', description: '从Huffman树回溯得到编码' },
|
|
|
|
|
|
{ path: 'c/ch4/huffman/halftree.c', name: 'halftree.c', label: 'Huffman树构建', description: '节点创建、合并、排序构建Huffman树' },
|
|
|
|
|
|
{ path: 'c/ch4/huffman/treelist.c', name: 'treelist.c', label: 'Huffman节点管理', description: '树节点创建和列表操作' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'bag',
|
|
|
|
|
|
label: '贪心背包',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch4/bag/tanbag.c', name: 'tanbag.c', label: '贪心背包', description: '部分背包问题的贪心解法' },
|
|
|
|
|
|
{ path: 'c/ch4/bag/tanbagtest.c', name: 'tanbagtest.c', label: '贪心背包测试', description: '贪心背包的测试/驱动' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'bestload',
|
|
|
|
|
|
label: '最优装载',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch4/bestload/loading.c', name: 'loading.c', label: '最优装载问题', description: '装载问题的贪心实现' },
|
|
|
|
|
|
{ path: 'c/ch4/bestload/sortAttr.c', name: 'sortAttr.c', label: '排序辅助', description: '装载问题排序比较器' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'money',
|
|
|
|
|
|
label: '找零问题',
|
|
|
|
|
|
files: [
|
2026-06-16 09:35:51 +08:00
|
|
|
|
{ path: 'c/ch4/money/getmoney.c', name: 'getmoney.c', label: '贪心找零', description: '按面额计算所需最少张数', pyPath: 'py/ch4/money/coin_change.py' },
|
2026-06-15 09:00:38 +08:00
|
|
|
|
{ path: 'c/ch4/money/moneytwowei.c', name: 'moneytwowei.c', label: '找零(二维)', description: '面额分解的另一版本' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'shortest',
|
|
|
|
|
|
label: '最短路径',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch4/shortest/path.c', name: 'path.c', label: '最短路径', description: '最短路径算法实现' },
|
|
|
|
|
|
{ path: 'c/ch4/shortest/shortpath.c', name: 'shortpath.c', label: '最短路径(分支界)', description: '分支界/分治的最短路径' }
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'ch5',
|
|
|
|
|
|
title: '第五章 回溯法',
|
|
|
|
|
|
subtitle: 'Backtracking — 搜索与剪枝',
|
|
|
|
|
|
description: '回溯法通过深度优先搜索所有可能的解,并在搜索过程中用剪枝函数避免无效搜索。本章涵盖0/1背包的回溯解法、装载问题、N皇后问题等。',
|
|
|
|
|
|
icon: '🔙',
|
|
|
|
|
|
topics: [
|
|
|
|
|
|
'回溯法基本思想',
|
|
|
|
|
|
'深度优先搜索',
|
|
|
|
|
|
'剪枝函数(约束函数与限界函数)',
|
|
|
|
|
|
'0/1背包的回溯解法',
|
|
|
|
|
|
'装载问题的回溯解法',
|
|
|
|
|
|
'N皇后问题'
|
|
|
|
|
|
],
|
2026-06-16 15:32:49 +08:00
|
|
|
|
knowledgeGraph: {
|
|
|
|
|
|
nodes: [
|
|
|
|
|
|
{ id: 'backtrack', label: '回溯法', desc: 'DFS + 剪枝' },
|
|
|
|
|
|
{ id: 'dfs', label: '深度优先搜索', desc: '沿着一条路径搜索到底' },
|
|
|
|
|
|
{ id: 'tree', label: '解空间树', desc: '所有可能解的树形表示' },
|
|
|
|
|
|
{ id: 'prune', label: '剪枝函数', desc: '提前终止无效分支' },
|
|
|
|
|
|
{ id: 'constraint', label: '约束函数', desc: '判断部分解是否可行' },
|
|
|
|
|
|
{ id: 'bound', label: '限界函数', desc: '判断是否可能优于已知最优' },
|
|
|
|
|
|
{ id: 'bkbag', label: '0/1背包(回溯)', desc: '选或不选 + 上界剪枝' },
|
|
|
|
|
|
{ id: 'bkload', label: '装载问题', desc: '搜索最优装载方案' },
|
|
|
|
|
|
{ id: 'nqueen', label: 'N皇后问题', desc: '棋盘上放置不攻击的皇后' }
|
|
|
|
|
|
],
|
|
|
|
|
|
edges: [
|
|
|
|
|
|
{ source: 'backtrack', target: 'dfs', label: '搜索策略' },
|
|
|
|
|
|
{ source: 'backtrack', target: 'tree', label: '搜索对象' },
|
|
|
|
|
|
{ source: 'backtrack', target: 'prune', label: '优化核心' },
|
|
|
|
|
|
{ source: 'prune', target: 'constraint', label: '可行性' },
|
|
|
|
|
|
{ source: 'prune', target: 'bound', label: '最优性' },
|
|
|
|
|
|
{ source: 'backtrack', target: 'bkbag', label: '应用' },
|
|
|
|
|
|
{ source: 'backtrack', target: 'bkload', label: '应用' },
|
|
|
|
|
|
{ source: 'backtrack', target: 'nqueen', label: '应用' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
2026-06-15 09:00:38 +08:00
|
|
|
|
subfolders: [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'hui01bag',
|
|
|
|
|
|
label: '回溯0/1背包',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch5/hui01bag/huisu01bag.c', name: 'huisu01bag.c', label: '0/1背包回溯解法', description: '递归回溯搜索最优解' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'loading',
|
|
|
|
|
|
label: '装载问题',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch5/loading/huiloading.c', name: 'huiloading.c', label: '回溯装载', description: '回溯搜索最佳放置方案' },
|
|
|
|
|
|
{ path: 'c/ch5/loading/loading2.c', name: 'loading2.c', label: '装载实现(二)', description: '装载问题的另一种回溯实现' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'queue',
|
|
|
|
|
|
label: 'N皇后',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch5/queue/nqueue.c', name: 'nqueue.c', label: 'N皇后问题', description: '回溯法解N皇后问题' }
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'ch6',
|
|
|
|
|
|
title: '第六章 分支限界法',
|
|
|
|
|
|
subtitle: 'Branch and Bound — 剪枝搜索最优解',
|
|
|
|
|
|
description: '分支限界法以广度优先或最小耗费优先的方式搜索解空间树,并用限界函数剪去不可能产生最优解的分支。本章涵盖图的BFS/DFS、0/1背包的分支限界解法、TSP问题等。',
|
|
|
|
|
|
icon: '🌿',
|
|
|
|
|
|
topics: [
|
|
|
|
|
|
'分支限界法基本思想',
|
|
|
|
|
|
'广度优先搜索与优先队列',
|
|
|
|
|
|
'上界函数与剪枝',
|
|
|
|
|
|
'0/1背包的分支限界解法',
|
|
|
|
|
|
'旅行商问题(TSP)',
|
|
|
|
|
|
'图的BFS与DFS遍历'
|
|
|
|
|
|
],
|
2026-06-16 15:32:49 +08:00
|
|
|
|
knowledgeGraph: {
|
|
|
|
|
|
nodes: [
|
|
|
|
|
|
{ id: 'bnb', label: '分支限界法', desc: 'BFS + 优先队列 + 剪枝' },
|
|
|
|
|
|
{ id: 'bfs', label: '广度优先搜索', desc: '按层逐级扩展' },
|
|
|
|
|
|
{ id: 'pq', label: '优先队列', desc: '按限界值选取扩展结点' },
|
|
|
|
|
|
{ id: 'livenode', label: '活结点表', desc: '待扩展的结点集合' },
|
|
|
|
|
|
{ id: 'upper', label: '上界函数', desc: '估算当前结点可达的最优值' },
|
|
|
|
|
|
{ id: 'bnbprune', label: '剪枝', desc: '上界 ≤ 当前最优则剪枝' },
|
|
|
|
|
|
{ id: 'bnbbag', label: '0/1背包(B&B)', desc: '上界剪枝搜索最优解' },
|
|
|
|
|
|
{ id: 'tsp', label: '旅行商问题', desc: '寻找最短环游路径' },
|
|
|
|
|
|
{ id: 'traversal', label: '图遍历', desc: 'BFS / DFS 遍历图' }
|
|
|
|
|
|
],
|
|
|
|
|
|
edges: [
|
|
|
|
|
|
{ source: 'bnb', target: 'bfs', label: '搜索方式' },
|
|
|
|
|
|
{ source: 'bnb', target: 'pq', label: '扩展策略' },
|
|
|
|
|
|
{ source: 'bnb', target: 'upper', label: '估值函数' },
|
|
|
|
|
|
{ source: 'bnb', target: 'bnbprune', label: '剪枝' },
|
|
|
|
|
|
{ source: 'bfs', target: 'livenode', label: '使用队列' },
|
|
|
|
|
|
{ source: 'pq', target: 'livenode', label: '管理结点' },
|
|
|
|
|
|
{ source: 'upper', target: 'bnbprune', label: '剪枝依据' },
|
|
|
|
|
|
{ source: 'bnb', target: 'bnbbag', label: '应用' },
|
|
|
|
|
|
{ source: 'bnb', target: 'tsp', label: '应用' },
|
|
|
|
|
|
{ source: 'bnb', target: 'traversal', label: '基础' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
2026-06-15 09:00:38 +08:00
|
|
|
|
subfolders: [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'xianbag01',
|
|
|
|
|
|
label: '分支限界0/1背包',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch6/xianbag01/bag01fifo.c', name: 'bag01fifo.c', label: '0/1背包(FIFO队列)', description: 'FIFO活结点队列的分支限界实现' },
|
|
|
|
|
|
{ path: 'c/ch6/xianbag01/bag01livevalue.c', name: 'bag01livevalue.c', label: '0/1背包(上界估计)', description: '用上界剪枝搜索最佳值的分支限界实现' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'tsp',
|
|
|
|
|
|
label: '旅行商问题(TSP)',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch6/tsp/fenzhi/tsp2.c', name: 'tsp2.c', label: 'TSP(分支限界)', description: '分支限界法解旅行商问题' },
|
|
|
|
|
|
{ path: 'c/ch6/tsp/huisu/travelroute.c', name: 'travelroute.c', label: 'TSP(回溯法)', description: '回溯法求解旅行商路径' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'graph',
|
|
|
|
|
|
label: '图遍历',
|
|
|
|
|
|
files: [
|
|
|
|
|
|
{ path: 'c/ch6/graph/bfs.c', name: 'bfs.c', label: '广度优先遍历(BFS)', description: '队列实现的图广度优先遍历' },
|
|
|
|
|
|
{ path: 'c/ch6/graph/dfs.c', name: 'dfs.c', label: '深度优先遍历(DFS)', description: '邻接矩阵/递归的图深度优先遍历' }
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取所有代码文件的扁平列表(含章节信息)
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function getAllFiles() {
|
|
|
|
|
|
const allFiles = []
|
|
|
|
|
|
for (const chapter of chapters) {
|
|
|
|
|
|
if (chapter.files) {
|
|
|
|
|
|
for (const file of chapter.files) {
|
|
|
|
|
|
allFiles.push({ ...file, chapterId: chapter.id, chapterTitle: chapter.title })
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (chapter.subfolders) {
|
|
|
|
|
|
for (const folder of chapter.subfolders) {
|
|
|
|
|
|
for (const file of folder.files) {
|
|
|
|
|
|
allFiles.push({ ...file, chapterId: chapter.id, chapterTitle: chapter.title, folder: folder.label })
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return allFiles
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function getChapterById(id) {
|
|
|
|
|
|
return chapters.find(ch => ch.id === id)
|
|
|
|
|
|
}
|