ZOJ 3349 Special Subsequence】的更多相关文章

Special Subsequence Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original ID: 334964-bit integer IO format: %lld      Java class name: Main There a sequence S with n integers , and A is a special subsequence that satis…
同 HDU 2836 只不过改成了求最长子串. DP+线段树单点修改+区间查最值. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #define lson l, m, rt << 1 #define rson m + 1, r, rt << 1 | 1 using namespace std; ; int n, d; int v…
Special Subsequence Time Limit: 5 Seconds      Memory Limit: 32768 KB There a sequence S with n integers , and A is a special subsequence that satisfies |Ai-Ai-1| <= d ( 0 <i<=|A|)) Now your task is to find the longest special subsequence of a ce…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3349 题意:给定一个数列,序列A是一个满足|Ai-Ai-1| <= d的一个序列,其中Ai为给定数列中的元素,要保持相对顺序,求最长的序列A. 显然用DP来解决,f[i]表示以第i个数结尾时的最长长度,则f[i]=Max{ f[j]+1 | j<i && |num[j]-num[i]|<=d }.直接转移复杂度O(n^2),超时.显然对于…
Common Subsequence Time Limit: 2 Seconds      Memory Limit: 65536 KB A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = <x1, x2, ..., xm> another sequence Z = <z1, z2, ..., zk…
题意:在给定的数组里,寻找一个最长的序列,满足ai-2+ai-1=ai.并输出这个序列. 很容易想到一个DP方程 dp[i][j]=max(dp[k][i])+1. (a[k]+a[i]==a[j],1<=k&&k<i) dp[i][j]表示序列最后两位是a[i],a[j]时的最长长度. 这个方程状态是O(n^2),转移是O(n),总复杂度是O(n^3)会超时. 进一步思考会发现转移这里是可以优化的.实际上我们只需要知道离i最近的那个满足a[k]+a[i]==a[j]的k就行,…
题目:给出一个序列,找出一个最长的子序列,相邻的两个数的差在d以内. /* 线段树优化dp dp[i]表示前i个数的最长为多少,则dp[i]=max(dp[j]+1) abs(a[i]-a[j])<=d 复杂度为O(n ^ 2) 利用线段树优化,线段树保存区间最大值.离散化后便可求出,还要注意 对于叶子节点保存的即为dp的值,每次更改即可,开始一直累加..... */ #include <iostream> #include <cstdio> #include <cst…
题意:黑先生新买了一栋别墅,可是里面的电灯线路的连接是很混乱的(每个房间的开关可能控制其他房间,房间数<=10),有一天晚上他回家时发现所有的灯(除了他出发的房间)都是关闭的,而他想回卧室去休息.可是很不幸,他十分怕黑,因此他不会走入任何关着灯的房间,于是请你帮他找出一条路使他既能回到卧室又能关闭除卧室以外的所有灯.如果同时有好几条路线的话,请输出最短的路线.(ZOJ是special judge,poj不是) 写起来有些纠结(实力太弱)...........先对各个房间的灯进行操作,再考虑向其他…
ZOJ 3406 Another Very Easy Task #include <cstdio> #include <cstring> const int N = 100005; char s[N]; int main() { bool f = 0; int size = 0; char ch; while(scanf("%c", &ch)!=EOF) { if( !(ch >= 'a' && ch <='z') &…
-----------------------------最优化问题------------------------------------- ----------------------常规动态规划  SOJ1162 I-Keyboard  SOJ1685 Chopsticks SOJ1679 Gangsters SOJ2096 Maximum Submatrix  SOJ2111 littleken bg SOJ2142 Cow Exhibition  SOJ2505 The County…
在网上总是查不到很系统的练ACM需要学习的数据结构资料,于是参考看过的东西,自己整理了一份. 能力有限,欢迎大家指正补充. 分类主要参考<算法竞赛入门经典训练指南>(刘汝佳),山东大学数据结构模板 ⊙基本数据结构 1.链表: 块状链表:没练过 Dancing Links:用于优化搜索.解决精确覆盖问题和重复覆盖问题的利器. Knuth教授的始祖论文:Dancing Links中文版 Dancing Links介绍(这篇对DLX的工作过程演示的很详细) DLX——Dancing Links(这篇…
Description There are eight planets and one planetoid in the Solar system. It is not a well known fact that there is a secret planet S4 inhabited by small creatures similar to bears, their codename being Lodas. Although this fact is well hidden from…
Greatest Common Increasing Subsequence 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1432 题目大意:给出两串数字,求他们的最长公共上升子序列(LCIS),并且打印出来. Sample Input 1 51 4 2 5 -124-12 1 2 4 Sample Output 21 4 分析:神奇就神奇在是LIS与LCS的组合 令dp[i][j]表示A串的前i个,与B串的前j…
Longest Ordered Subsequence Time Limit: 2 Seconds      Memory Limit: 65536 KB A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK), whe…
POJ:http://poj.org/problem?id=1458 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=733 HDU: http://acm.hdu.edu.cn/showproblem.php?pid=1159 题目大意: 给定两串子序列,求最长的公共字串(LCS) 设d( i , j)为A和 B的LCS的长度,则当A[i] = B[j]时, d(i , j)= d(i-1, j-1)+1 ; 否则…
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3702 题目大意: 对于给定的一个字符串,满足如下要求输出AC,否则WA(好吧我简写) 给定字符串只有ZOJ三个字母组成.Z和J只能有一个并且Z在左边 J之后的O个数必须大于Z之前的O个数 Z和J之间O的个数必须不大于J之后的O的个数,并且他们都大于0 #include<cstdio> #include<cstring> const int MAXN=1001;…
#include<time.h> #include <cstdio> #include <iostream> #include<algorithm> #include<math.h> #include <string.h> #include<vector> #include<queue> using namespace std; ],a[]; int len,i,k,n,m; int binary(int t)…
传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1136 题目大意:给定一串序列,求最长的升序列长度,如1, 7, 3, 5, 9, 4, 8 最长的为 1, 3, 5, 8 输出4 进行DP,设dp [ i] 为 以 i 结尾的升序列的最大值,那么从 i 开始向前查找,若 a[ j ] < a [ i ] 则 比较一下 dp的大小 一开始我只找最靠近它的比它小的数,wa了一次. 如: 1 9 1 9 2 10 11…
传送门 $Description$ 求两个序列的最长公共上升子序列 $Solution$ $f[i][j]$表示$a$序列匹配到$i$和$b$序列匹配到$j$的最长上升序列的长度,这里并不要求$a[i]==b[j]$. 两层循环,外层$i=1...n1$,内层$j=1...n2$ 转移: $f[i][j]=max(f[i-1][1...j-1](if\  b[j]<a[i]))+1$ 这里的$max(f[i-1][i...j-1](if\  b[j]<a[i]))$不用每次单独枚举,只要在循环…
题意:给定N个数,求和大于等于S的最短连续子序列的长度. 分析:滑动窗口即可.两种写法. 1. #include<cstdio> #include<cstring> #include<cstdlib> #include<cctype> #include<cmath> #include<iostream> #include<sstream> #include<iterator> #include<algor…
Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) string, and s is a short string (<=100). A subsequence of…
A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fewer than two…
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array. Formally the function should: Return true if there exists i, j, k such that arr[i] < arr[j] < arr[k] given 0 ≤ i < j < k ≤ n-1 else return…
Longest Increasing Subsequence Given an unsorted array of integers, find the length of longest increasing subsequence. For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101], therefore the length is 4. Not…
3860 - Find the Spy Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3860 Description Whoooa! There is a spy in Marjar University. All we know is that the spy has a special ID card. Please find him…
题目链接: 题目 Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) 问题描述 This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence. 输入 Each sequen…
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并查集======================================[HDU]1213   How Many Tables   基础并查集★1272   小希的迷宫   基础并查集★1325&&poj1308  Is It A Tree?   基础并查集★1856   More i…
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1423 Problem Description This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence.   Input Each sequence is described with M - its length (1 <= M <= 500) and…
链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1010 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=29328#problem/B Area Time Limit: 2 Seconds       Memory Limit: 65536 KB       Special Judge Jerry, a middle school student, ad…
题目连接:problemId=542" target="_blank">ZOJ 1542 POJ 1861 Network 网络 Network Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Andrew is working as system administrator and is planning to establish a new network in his com…