随笔分类 -  DP

CF Mysterious Present最长上升子序列(未完)
摘要:链接:http://codeforces.com/problemset/problem/4/D题意:有一张卡片,若干张信封,它们有个长和宽。要求,找到数量最多的一串信封,这一串信封满足信封的长和宽都是严格递增的,而且卡片的长和宽要比最小的信封小。思路:先对长度排个序,然后求宽度的最长上升子序列。要处理好长度相等的信封。#include#include#include#include#include#include#includeusing namespace std;const int maxn=5005;int dp[maxn],c[maxn];struct en{ int w,h,f... 阅读全文
posted @ 2013-08-19 21:06 ∑求和 阅读(290) 评论(0) 推荐(0)
zoj1986,poj1631,最长上升子序列,复杂度O(n*logn)
摘要:链接:http://poj.org/problem?id=1631题意:最长上升子序列。复杂度为O(n*logn).思路:这道题只能用nlogn的算法,n^2的话会卡掉。下面这两个个链接介绍nlogn的算法讲的还可以。http://www.cnblogs.com/celia01/archive/2012/07/27/2611043.htmlhttp://blog.sina.com.cn/s/blog_4b1e4fe9010098af.html代码如下:#include#include#include#include#include#include#includeusing namespace 阅读全文
posted @ 2013-08-19 15:51 ∑求和 阅读(194) 评论(0) 推荐(0)
zoj2136最长上升子序列,复杂的O(n^2)
摘要:链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1136题意:裸的最长上升子序列。复杂度O(n^2).#include#include#include#include#include#include#includeusing namespace std;const int maxn=1005;int n;int a[maxn],dp[maxn];int LIS(){ dp[0]=1; int ans=1; for(int i=1;is && a[j]ans) ans=dp[i];... 阅读全文
posted @ 2013-08-19 11:21 ∑求和 阅读(192) 评论(0) 推荐(0)
hdu4681 DP,最长公共子序列
摘要:链接:http://acm.hdu.edu.cn/showproblem.php?pid=4681题意:给三个串a,b,c,要求找到一个最长的d串,满足d是a和b的字串,c是d的子序列。思路:大体是把a,b串分为三个部分,中间一部分是包含c的子串,要想要d最长,所以中间这一截长度要最小,所以这一截的开始要是c[0],结尾要是c[n-1],枚举出这些个位置。假设这个串在a,b中的首尾位置分别为ai,aj,bi,bj,再求出ai,bi之前最长公共子序列的长度dp[i-1][j-1],ai,bi之后最长公共子序列的长度dp[i+1][j+1],答案为这两个公共子序列的长度加上c的长度的最大值。 阅读全文
posted @ 2013-08-17 19:29 ∑求和 阅读(132) 评论(0) 推荐(0)
CF331C1暴力
摘要:链接:http://codeforces.com/problemset/problem/331/C1题意:省略它。。。思路:暴力,没什么好说的。话说C2,C3是不是要用数位DP来做呢?以后学了再做做吧。#include#include#includeusing namespace std;int main(){ int n,m,k,maxn,ans=0; int s[7]; cin>>n; while(n) { m=n;k=0; while(m) { s[k++]=m%10; m... 阅读全文
posted @ 2013-07-19 19:31 ∑求和 阅读(417) 评论(0) 推荐(0)