- 博客(12)
- 资源 (1)
- 收藏
- 关注
原创 组合问题:全组合和C(n,m)
问题: 1.数组a[1~n],生成数组中所有元素的组合。 2.生成C(n,m)组合问题一:全组合思想: 数组长度为4,用4位2进制:0000~1111,二进制位为1表示选取该位元素,0表示不选。 代码://nums数组长度为n,mask为n位二进制掩码,二进制位为0,则选取该对应元素vector<int> getCombByMask(vector<int> nums,int mask,int
2015-09-29 23:35:50 792
原创 全排列问题:序号与排列转换
问题:全排列按字典序排序,每个排列都对应有一个序号。1.根据序号求排列;2.根据排列求序号。思想:n的阶乘的进制思想,从前往后一次是n!, (n-1)!, …, 2!, 1!。代码:1.根据排列求序号//一个排列在字典序全排列中的序号,输入:一个排列,输出:排列的序号int perm2num(vector<int> p){ int n=p.size(); int num=0;
2015-09-29 17:35:54 2234
原创 全排列生成算法
问题:生成1~n的全排列(生成一个数组中所有元素的全排列)。方法一:字典序方法思想:依据字典序顺序,由前一个排列,生成后一个排列。 代码://字典序方法:输入前一个排列,输出后一个排列vector<int> &nextPermutation(vector<int> &p){ unsigned long left,right; left=right=p.size()-1; w
2015-09-29 17:28:49 454
原创 网易163邮箱配置-iOS、OS X邮箱客户端
最近处于找工作阶段,收邮件比较头疼,我用了foxmail邮箱和163邮箱,想用一个客户端收邮件。我个人常用foxmail,但是像应聘360和网易等还是用163的邮箱比较好。本人是轻度强迫症患者:想让自己的MacBook Pro和iPhone 6s的邮件客户端能同时连接上foxmail和163,这样收发邮件就很方便。不想用网易的邮箱大师客户端,还有一个原因是邮箱大师没有mac版。连接foxmail比较
2015-09-26 14:24:40 27955
原创 leetcode 3 Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For “
2015-09-22 19:08:43 362
原创 leetcode 152 Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4], the contiguous subarray [2,3] has the largest produ
2015-09-22 18:17:32 373
原创 leetcode 53 Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1] has the
2015-09-22 16:51:17 279
原创 不小于N的素数个数
不小于N的素数个数使用eratosthenes algorithm算法。 算法思想:从2~n遍历,过滤到素数的倍数,没有被过滤的就是素数。//eratosthenes algorithmint countPrimes(int n) { //使用0和1两种状态就OK vector<int> vn(n,1); int count=0; for(int i=2;i<n;
2015-09-18 22:55:13 863
原创 leetcode 220 Contains Duplicate III
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i and j is
2015-09-14 19:43:12 330
原创 leetcode 76 Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example, S = “ADOBECODEBANC” T = “ABC” Minimum window is “BANC”.Note:
2015-09-14 19:38:21 357
转载 硬币面值组合问题
问题描述 假设我们有8种不同面值的硬币{1,2,5,10,20,50,100,200},用这些硬币组合够成一个给定的数值n。例如n=200,那么一种可能的组合方式为 200 = 3 * 1 + 1*2 + 1*5 + 2*20 + 1 * 50 + 1 * 100. 问总过有多少种可能的组合方式? (这道题目来自著名编程网站ProjectEuler, 点击这里查看原题目) 类似的题目还有:
2015-09-14 18:03:07 1298
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人