自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(12)
  • 收藏
  • 关注

原创 python中的递归memoize加速

memoize

2022-07-04 15:28:06 285 1

原创 【CS61A】count_partition(整数划分)

CS61A

2022-07-02 17:01:48 519 1

原创 Warnsdorff算法(骑士周游问题)

/* * File: KnightsTour.cpp * --------------------- * This program find a knight's tour on an N x M chessboard. */#include "KnightsTour.h"/* * Function: solveKnightsTour * Usage: solveKnightsTour(n, m); * ------------------------------ * Solves

2022-05-15 21:32:12 354

原创 MIPS和C语言的简单转换

C语言函数:int leaf_example(int g, h, i, j){ f = (g + h) - (i + j); return f;}转换为MIPS并输出结果:.data newLine: .asciiz "\n" .text main: addi $a0, $zero, 10 addi $a1, $zero, 30 addi $a2, $zero, 10 addi $a3, $zero, 0 jal leaf_example li $

2021-12-06 17:11:05 2981

原创 特殊的快速排序

#include <iostream>using namespace std;const int CUTOFF = 5;void insertionSort(int a[], int left, int right) { for (int j = left + 1; j < right + 1; ++j) { int key = a[j]; int i = j - 1; while (i >= 0 &&amp

2021-07-08 03:29:31 135

原创 比较快速排序和归并排序

虽然归并排序和快速排序的时间复杂度都为O(nlogn),但实际上快速排序的速度会比归并排序快2-3倍,原因如下:1.归并排序在执行时,需要一个额外的temp数组去拷贝原数组的数据,会大量占用程序的空间。2.快速排序再运行时,实际上是直接再原数组进行递归操作,并不会占用额外的空间。...

2021-07-07 18:38:26 1390

原创 算法导论(快速排序)

1.pivot为数组的最后一个数。2.使用一个for循环就能完成partition部分。package algorithm.sort;import java.util.Arrays;public class Quicksort { public static void main(String[] args) { int[] arr = {-9,78,0,23,-587,70}; QUICKSORT(arr, 0, arr.length-1);

2021-07-05 20:33:29 104

原创 逆波兰表达式(栈实现)

#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stack> #include <stdlib.h> using namespace std;stack <long long> q;int main() { int c = 1000000007; bool error

2021-07-04 02:36:16 390

原创 括号匹配问题(栈实现)

import java.util.Scanner;public class LinkStack { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Please input:"); String str = scanner.nextLine(); System.out.prin

2021-07-04 02:28:27 157

原创 Java求解最大子数组问题(分治法)

import java.util.Arrays;public class MaxSubarray { public static void main(String[] args) { int[] arr = {13, -3, -25, 20, -3, -16, -23, 18, 20, -7, 12, -5, -22, 15, -4, 7}; System.out.println(Arrays.toString(FindMaxSubarray(arr, 0, ar

2021-07-03 21:12:19 313

原创 递归实现选择排序

递归实现选择排序```javapublic static void re_selectSort(int[] arr, int point){ if (point<arr.length) { int minIndex = point; int min = arr[point]; for (int i = point; i < arr.length; i++) { if (min > arr[i]) {

2021-07-03 19:07:42 297

原创 递归实现插入排序

import java.util.Arrays;public class InsertSort {public static void main(String[] args) { int[] arr = {102,34,119,1,-1,89}; insertSort(1, 1, arr); System.out.println(Arrays.toString(arr));}public static void insertSort(int n, int m, int[]

2021-06-11 12:15:07 132 1

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除