比较简单的DP,用记忆化搜索比较简单,递推。。。应该不好写吧 。
很容易发现,对于同一个位置,它的最长路是一定的, 不会变的,因为路是递减的,所以该题很适合用记忆化搜索 。 由此我们也可以发现DP和搜索的联系 。
代码如下:
#include
using namespace std;
int T,r,c,a[105][105],d[105][105];
int dx[] = {0,1,...
分类:
其他好文 时间:
2015-07-17 22:47:06
阅读次数:
122
#ifndef LONG_PATH_H#define LONG_PATH_H#include#include#define MAX 65535int graphPath_longest(int (*Graph)[5],int Length,int origin,int destin ); void ...
分类:
其他好文 时间:
2015-07-17 20:54:10
阅读次数:
212
#ifndef PALINDROME_H_#define PALINDROME_H_#include#includeint palindrome_longest(char *str,int front,int back); #endif #include"Palindrome.h"#define M...
分类:
其他好文 时间:
2015-07-17 20:52:05
阅读次数:
238
Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called a reduced proper fraction.
If we list the set of reduced proper fractions for d ≤ 8 in ascending or...
分类:
其他好文 时间:
2015-07-17 16:26:05
阅读次数:
130
题目:
Write a function to find the longest common prefix string amongst an array of strings.
就是要求一些字符串的最长公共前缀。
code:
class Solution {
public:
string longestCommonPrefix(vector& strs) {...
分类:
其他好文 时间:
2015-07-17 14:09:38
阅读次数:
116
原题Throwing cards away I Given is an ordered deck ofn cards numbered 1 to n with card 1 at the top and card n at the bottom. Thefollowing operation is....
这个题目。。。。想上题意10935 Throwing cards away IGiven is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The follow...
分类:
其他好文 时间:
2015-07-16 23:55:35
阅读次数:
156
Description A numeric sequence of ai is ordered if a1 #include #include using namespace std;int main(){ int n,i,j,a[1005],d[1005]; while(scanf("...
分类:
其他好文 时间:
2015-07-16 19:05:49
阅读次数:
104
很经典的题目,求字符串中的最长回文子串。
(1)最朴素的解法 ---暴力 复杂度O(N³)
这也是最容易想到的方法,最外层循环枚举起点i,第二层循环从i+1开始向后枚举,第三层判断是不是回文串。最后取最长子串的返回。
代码比较简单,这里没有列出。
(2)中心扩展法。复杂度O(N²)
枚举每一个字符作为中心点向左右扩展。但是这里要注意,对于每一次扩展要分奇偶两种情况。否则可能会漏掉情况。
...
分类:
其他好文 时间:
2015-07-16 09:52:23
阅读次数:
141
现在还不是总结动态规划的时候,这次遇到了动态规划的新的一种:矩阵法(自己创的),可以是一维也可以是二维,更多为很少见。随着刷题量的增大,务必好好总结动态规划是什么,有哪些种类。class Solution {
public:
string longestPalindrome(string s) { int length = s.size();
int arr[1...
分类:
其他好文 时间:
2015-07-15 22:56:32
阅读次数:
132