- 博客(5)
- 收藏
- 关注
原创 找零钱问题中动态优化的空间复杂度优化
找零钱问题假设,老王有N张纸币,纸币的面值用arr[N]表示,现在老王要给隔壁的老李M元钱,请问,如何组合手中的纸币,使给出的纸币张数最少?如果可以,返回最少的纸币张数,否则返回-1。问题分析 假如要给老李10元钱,老王的手中又有一张5元的纸币,那么,能使用该5五元钱的的情况必须是其他的纸币能组合成剩下的5元钱。 -》 动态规划问题!!! 基础算法,用一个 N*(M+1) 维的数组res来作为状
2016-06-13 22:15:16 848
转载 类斐波那契问题中动态规划的时间复杂度优化
关键思路 (1)从递推公式求解状态转移方程->转移矩阵 f(n)= f(n-1)+f(n-2) [f(n),f(n-1)] = [ f(1), f(2)] * [(1,1);(1,0)]^(n-2) (2)优化求矩阵的幂问题!!!#include <iostream>using namespace std; void matrixMulti(int const m1[][
2016-06-13 11:36:22 1091
原创 leetcode之palindrome-partitioning-ii(动态规划)
题目描述Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. For example, given s =”aab”, Return1s
2016-06-12 19:38:16 654
原创 leetcode之single number
Question: Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it wit
2016-06-12 15:09:47 354
转载 c++中string 与 double或int之间的转换
1、使用c标准库 atoi(); atof();#include <cstdlib>#include <iostream>#include <string>int main(){ string str = "123"; int num_int = atoi(str.c_str()); if (errno == ERANGE) //可能是std::er
2016-06-03 22:14:18 1135
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人