- 博客(10)
- 收藏
- 关注
原创 不考虑价值的背包问题
背包问题:假设有一个能装入总体积为T的背包和n件体积分别为W1,W2,…,Wn的物品, 能否从n件物品中挑选若干件恰好装满背包, 使W_i1+W_i2+…+W_in=T,要求找出所有满足上述条件的解。#include<iostream>#include<vector>#include<stack>using namespace std;struct
2017-12-28 15:21:05 3074
原创 安全hash算法,sha-1的C++实现
#include<iostream>#include<string>#include<vector>#include<cmath>#include<stack>using namespace std;#define NUM 8 //一个字等价于8个16进制数 #define HEX 16 //16进制 #define BIT 512 //消息认证码512 bite一组class
2017-12-10 14:00:39 3119 1
原创 8.8 精确的4SAT问题的NP-完全性证明
问题:在精确的 4SAT 问题中,输入为一组子句,,每个字句都是恰好4个文字的析取,且每个变量最多在每个子句中出现一次。目标是求它的满足赋值——如果该赋值存在。证明精确的 4SAT 是NP-完全问题。证明如下:由于 3SAT 问题是 NP - 完全问题,所以如果能够从 3SAT 归约到精确的 4SAT 问题,那么精确的 4SAT 问题也是 NP - 完全问题。下面是归约过程:第一步
2017-07-11 15:15:24 613
原创 Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.Example 1
2017-06-12 23:15:25 213
原创 动态规划问题
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRan
2017-05-15 19:53:26 204
原创 sort算法案例
题目:Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element in the result must be unique.
2017-04-10 19:44:32 312
原创 graph
问题:Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return the answers. If
2017-03-20 17:55:05 173
原创 简单分治案例
题目:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the
2017-03-13 13:11:35 226
原创 简单归并排序
问题:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, r
2017-03-05 17:34:58 304
原创 简单算法解答
题目:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use
2017-02-26 14:40:38 268
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人