题意:在给定的数组里,寻找一个最长的序列,满足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就行,…
两题水题: 1.如果一个数能被分解为两个素数的乘积,则称为Semi-Prime,给你一个数,让你判断是不是Semi-Prime数. 2.定义F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2) 让你判断第n项是否能被3整除. 1.ZOJ 2723 Semi-Prime http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1723 打表即可. #include<cstdio>…
A sequence X_1, X_2, ..., X_n is fibonacci-like if: n >= 3 X_i + X_{i+1} = X_{i+2} for all i + 2 <= n Given a strictly increasing array A of positive integers forming a sequence, find the length of the longest fibonacci-like subsequence of A.  If on…
[LeetCode]873. Length of Longest Fibonacci Subsequence 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/length-of-longest-fibonacci-subsequence/description/ 题目描述: A sequence X_…
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…
题目地址: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…
2017-08-06 15:41:04 writer:pprp 刚开始学dp,集训的讲的很难,但是还是得自己看,从简单到难,慢慢来(如果哪里有错误欢迎各位大佬指正) 题意如下: 给两个字符串,找到其中大的公共子序列,每个样例输出一个数: 最长公共子串(Longest Common Substirng)和最长公共子序列(Longest Common Subsequence,LCS)的区别为: 子串是串的一个连续的部分,子序列则是从不改变序列的顺序,而从序列中去掉任意的元素而获得新的序列: 也就是说…
原题链接在这里:https://leetcode.com/problems/length-of-longest-fibonacci-subsequence/ 题目: A sequence X_1, X_2, ..., X_n is fibonacci-like if: n >= 3 X_i + X_{i+1} = X_{i+2} for all i + 2 <= n Given a strictly increasing array A of positive integers forming…
斐波那契数列定义 Fibonacci array:1,1,2,3,5,8,13,21,34,... 在数学上,斐波那契数列是以递归的方法来定义: F(0) = 0 F(1) = 1 F(n) = F(n-1) + F(n-2) 用文字描述,就是斐波那契数列由0和1开始,之后的斐波那契系数就是由之前的两数之和想加而得,首几个斐波那契数列系数是:0,1,1,2,3,5,8,13,21,34,55,...特别指出:0不是第一项,而是第零项. 递归解法 最容易想到的解法自然是按照公式的递归解法,具体实现…
Problem Description 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> is a subsequence of X if there exists a stri…