1.题目描述:点击打开链接
2.解题思路:本题是一道动态规划题,不过可以直接进行暴力搜索,和上次CF的ZeptoLab的C题完全一样,不再赘述。
3.代码:
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
#include
#include
#include
#include
#inc...
分类:
其他好文 时间:
2015-04-11 08:59:59
阅读次数:
120
Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest...
分类:
其他好文 时间:
2015-04-11 01:18:51
阅读次数:
113
题目:leetcode
Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.
For example,
Given:
s1 = "aabcc",
s2 = "dbbca",
When s3 = "aadbbcb...
分类:
编程语言 时间:
2015-04-10 22:34:40
阅读次数:
207
已知一些单词,选择其中一些单词组成目的字符串,问共有多少种方法。其实初看到这道题,自然而然地可以想到动态规划中经典的硬币问题:例如,问1元,2元,5元,总共有多少种方法能组成20元?这里不过是把硬币换成了单词而已。但是,如果真的只是像硬币问题一样每个单词都轮询一遍,显然太慢了,最多要有300000*4000*100次比对。
假如利用trie数的话,至多只要比对100次,就能找到所有...
分类:
其他好文 时间:
2015-04-10 22:08:29
阅读次数:
123
题意:
给定n个数,问你将他们修改成非增或非减序列的最小花费。最小花费的定义是
假设原数组为 a[1] a[2] a[3] .... a[n]
修改后数组为 b[1] b[2] b[3] .... b[n]
那么最小花费为|a[1]-b[1]|+|a[2]-b[2]|+| a[3] - b[3] |+.....| a[n] - b[n] |.
思路:
线性结构上的动态规划 定义状态d...
分类:
其他好文 时间:
2015-04-10 22:06:43
阅读次数:
125
最长回文子串:1. 暴力搜索 时间复杂度O(n^3)2. 动态规划dp[i][j] 表示子串s[i…j]是否是回文初始化:dp[i][i] = true (0 i) ? min(p[j], mx-i) : 0; while (cstr[i + p[i] + 1] == cs...
分类:
其他好文 时间:
2015-04-10 19:50:56
阅读次数:
98
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)
You have the following 3 operations permitted on a word:...
分类:
其他好文 时间:
2015-04-10 17:57:11
阅读次数:
171
1 #include 2 #include 3 int a[10000][10000]; 4 void huan(int row,int len) 5 { 6 int i,j; 7 for(i=0; i<len/2; i++) 8 { 9 for(j=0...
分类:
其他好文 时间:
2015-04-10 17:39:50
阅读次数:
167
回溯法又称试探法。回溯法的基本做法是深度优先搜索,是一种组织得井井有条的、能避免不必要重复搜索的穷举式搜索算法。回溯算法的基本思想是:从一条路往前走,能进则进,不能进则退回来,换一条路再试。当我们遇到某一类问题时,它的问题可以分解,但是又不能得出明确的动态规划或是递归解法,此时可以考虑用回溯法解决此...
分类:
其他好文 时间:
2015-04-10 17:22:39
阅读次数:
110
题目:如图所示, 3 2 3 4 3 4 47个数字构成三层的数字三角形,从属关系为树形关系。要求按照从属关系,在每一层选择一个数,使最后的和最大。分析:如果从下往下选择的话,越往下选择越多,问题就越复杂。考虑从下往上选择,采用动态规划法,从局部开始考虑。局部最大,则构成整体最大。我是用C++写的....
分类:
其他好文 时间:
2015-04-10 17:15:14
阅读次数:
156