CO-PRIME时间限制:1000ms | 内存限制:65535KB难度:3描述This problem is so easy! Can you solve it?You are given a sequence which contains n integers a1,a2……an, your t...
分类:
其他好文 时间:
2014-08-10 10:18:40
阅读次数:
250
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=46用类似于快速幂的方法做,注意1的时候是0;#include using namespace std;int main(){ int ase; int num; int r...
分类:
其他好文 时间:
2014-08-10 10:16:10
阅读次数:
317
本题就是一题LIS(最长递增子序列)的问题。本题要求求最长递增子序列和最长递减子序列。
dp的解法是O(n*n),这个应该大家都知道,不过本题应该超时了。
因为有O(nlgn)的解法。
但是由于本题的数据特殊性,故此本题可以利用这个特殊性加速到O(n)的解法,其中的底层思想是counting sort分段的思想。就是如果你不会counting sort的话,就很难想出这种优化的算法了。
...
分类:
其他好文 时间:
2014-08-09 23:18:49
阅读次数:
393
题意 求n个数字的和最大的递增子序列
基础的dp题目 令d[i]表示以第i个数字结尾的和最大的递增子序列 有d[i]=max(d[i],d[j]+a[i]) j为1到a之间的数 且a[i]>a[j]...
分类:
其他好文 时间:
2014-08-09 21:34:49
阅读次数:
202
第三版《算法导论》动态规划新增题目之求最长回文子序列。只要能看到书中LCS代码,这个问题就能解决。...
分类:
其他好文 时间:
2014-08-09 18:48:28
阅读次数:
330
CO-PRIME
时间限制:1000 ms | 内存限制:65535 KB
难度:3
描述
This problem is so easy! Can you solve it?
You are given a sequence which contains n integers a1,a2……an, your task is to find how man...
分类:
其他好文 时间:
2014-08-09 18:46:38
阅读次数:
244
Compress String
时间限制:2000 ms | 内存限制:65535 KB
难度:3
描述
One day,a beautiful girl ask LYH to help her complete a complicated task—using a new compression method similar to Run Length Encod...
分类:
其他好文 时间:
2014-08-09 18:46:18
阅读次数:
284
经常会遇到复杂问题不能简单地分解成几个子问题,而会分解出一系列的子问题。简单地采用把大问题分解成子问题,并综合子问题的解导出大问题的解的方法,问题求解耗时会按问题规模呈幂级数增加。
为了节约重复求相同子问题的时间,引入一个数组,不管它们是否对最终解有用,把所有子问题的解存于该数组中,这就是动态规划法所采用的基本方法。
【问题】 求两字符序列的最长公共字符子序列
问题描述:字符序列的子...
分类:
其他好文 时间:
2014-08-09 18:46:08
阅读次数:
288
一、什么是最长公共子序列 什么是最长公共子序列呢?举个简单的例子吧,一个数列S,若分别是两个或多个已知序列的子序列,且是所有符合条件序列中最长的,则S称为已知序列的最长公共子序列。 举例如下,如:有两个随机数列,1 2 3 4 5 6 和 3 4 5 8 9,则它们的最长公共子序列便是:3 4 5....
分类:
其他好文 时间:
2014-08-09 18:15:58
阅读次数:
311
1. 动态规划,使用一个数组保存当前的最大递增子序列长度,时间复杂度为O(N^2)
# include
# include
# include
using namespace std;
int longestsub(int a[],int n)
{
int *dis=(int *)malloc((n+1)*sizeof(int));
dis[0]=1;
int i,j;
for(...
分类:
其他好文 时间:
2014-08-09 13:30:07
阅读次数:
221