
算法
算法导论我去
我喜欢写代码^-^
展开
-
第一次实验
题目和解答都在代码里:/* * CS:APP Data Lab * * bits.c - Source file with your solutions to the Lab. * This is the file you will hand in to your instructor. * */#include #include #include #in原创 2016-03-23 23:40:11 · 7345 阅读 · 0 评论 -
(p226)最长公共子序列
#include#include#include#define max 100const char lu[4]={0xe2,0x86,0x96},u[4]={0xe2,0x86,0x91},l[4]={0xe2,0x86,0x90};int LCS_LENGTH(char x[],char y[],int c[][max+1],int b[][max+1],int m,int n){原创 2016-03-25 09:07:04 · 303 阅读 · 0 评论 -
p(343)通用汇点
i\j 0 1 2 3 4 0 0 0 1 0 1 1 0 0 1 0 0 2 0 0 0 0 0 3 0 0 1 0 0 4 0 0 1 0 0这个算法的运行时间是O(V) - 首先,a[i][i]=0,因此算法走过的路径都在主对角线及以上 - 若a[i]原创 2016-03-29 09:09:30 · 548 阅读 · 0 评论 -
排序算法大合集
#include<stdlib.h>#include<unistd.h>#include<stdio.h>#include<unistd.h>#include<sys/wait.h>#include<time.h>#define MAX 10000int check(int a[],int n){ for (int i=0;i<n-1;i++) if (a[i]>原创 2017-12-22 14:58:20 · 195 阅读 · 0 评论 -
最长递增子序列(nlogn)
#define MAX 1000000int find(int a[],int x,int l,int r){ while (l<=r){ int mid=(l+r)/2; if (a[mid]==x) return mid; if (a[mid]<x) l=mid+1; els原创 2017-12-22 19:30:05 · 851 阅读 · 0 评论 -
kmp算法
#define MAX 10000void getNext(char *p,int next[]){ int p_len=strlen(p); next[0]=-1; next[1]=0; for (int i=2;i<p_len;i++){ int q=next[i-1]; while (q!=0 && p[q]!=p[i-1])原创 2017-12-23 00:20:48 · 162 阅读 · 0 评论 -
514. Paint Fence
class Solution {public: /* * @param n: non-negative integer, n posts * @param k: non-negative integer, k colors * @return: an integer, the total number of ways */ int numWa原创 2017-12-24 11:16:09 · 181 阅读 · 0 评论 -
109.triangle
class Solution: """ @param: triangle: a list of lists of integers @return: An integer, minimum path sum """ def minimumTotal(self, triangle): # write your code here原创 2017-12-24 11:31:50 · 205 阅读 · 0 评论 -
110.Minimum Path Sum
class Solution: """ @param: grid: a list of lists of integers @return: An integer, minimizes the sum of all numbers along its path """ def minPathSum(self, grid): # write yo原创 2017-12-24 11:41:41 · 184 阅读 · 0 评论