poj 1952 最长公共子序列计数
看代码就懂了 不解释 3 1 1 1 1 2 2 2 1 1 1 3 第一个3 和最后一个 3 只需要一个就够了,,,
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stdio.h>
#include<cmath>
using namespace std; int dp[],num[],arr[];
int main( )
{
int N; scanf("%d",&N);
for( int i = ; i <= N; i++ )
{
scanf("%d",&arr[i]);
dp[i] = num[i] = ;
}
int Max = ;
for( int i = ; i <= N; i++ )
for( int j = i-; j >= ; j-- )
if( arr[i] < arr[j] )
{
if( dp[j]+ > dp[i] )
{
dp[i] = dp[j]+;
num[i] = num[j];
}else if( dp[j]+ == dp[i] )
num[i] += num[j];
}else if( arr[i] == arr[j] )
{
if( dp[i] == )num[i] = ;
break;
}
for( int i = ; i <= N; i++ )
Max = max( Max,dp[i] );
int res = ;
for( int i = ; i <= N; i++ )
if( dp[i] == Max )res+=num[i];
cout<<Max<<" "<<res<<endl;
return ;
}
poj 1952 最长公共子序列计数的更多相关文章
- POJ 1458 最长公共子序列(dp)
POJ 1458 最长公共子序列 题目大意:给出两个字符串,求出这样的一 个最长的公共子序列的长度:子序列 中的每个字符都能在两个原串中找到, 而且每个字符的先后顺序和原串中的 先后顺序一致. Sam ...
- ACM/ICPC 之 最长公共子序列计数及其回溯算法(51Nod-1006(最长公共子序列))
这道题被51Nod定为基础题(这要求有点高啊),我感觉应该可以算作一级或者二级题目,主要原因不是动态规划的状态转移方程的问题,而是需要理解最后的回溯算法. 题目大意:找到两个字符串中最长的子序列,子序 ...
- POJ 1458 最长公共子序列
子序列就是子序列中的元素是母序列的子集,且子序列中元素的相对顺序和母序列相同. 题目要求便是寻找两个字符串的最长公共子序列. dp[i][j]表示字符串s1左i个字符和s2左j个字符的公共子序列的最大 ...
- POJ 1458 最长公共子序列 LCS
经典的最长公共子序列问题. 状态转移方程为 : if(x[i] == Y[j]) dp[i, j] = dp[i - 1, j - 1] +1 else dp[i, j] = max(dp[i - 1 ...
- POJ 2250(最长公共子序列 变形)
Description In a few months the European Currency Union will become a reality. However, to join the ...
- 【简单dp】poj 1458 最长公共子序列【O(n^2)】【模板】
最长公共子序列可以用在下面的问题时:给你一个字符串,请问最少还需要添加多少个字符就可以让它编程一个回文串? 解法:ans=strlen(原串)-LCS(原串,反串); Sample Input abc ...
- POJ 1159 Palindrome-最长公共子序列问题+滚动数组(dp数组的重复利用)(结合奇偶性)
Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...
- Human Gene Functions POJ 1080 最长公共子序列变形
Description It is well known that a human gene can be considered as a sequence, consisting of four n ...
- Common Subsequence POJ - 1458 最长公共子序列 线性DP
#include <iostream> #include <algorithm> #include <string> #include <cstring> ...
随机推荐
- 杭电1021Fibonacci Again
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1021 题目: Problem Description There are another kind of ...
- Maven的Mirror和Repository
今天新公司入职,项目经理让迁出项目,心想maven的阿里镜像源挺快的,干脆在配置了公司私服之后自己配置了阿里的镜像源,没成想项目屡屡报错,找不到项目依赖的公司jar包,后来才发现,同事配置mirror ...
- 2018年Java面试题搜集
2018年Java面试题搜集 一.Servlet执行流程(浏览器访问servlet的过程容器) 客户端发起http请求,web服务器将请求发送到servlet容器,servlet容器解析url并根据w ...
- 如何用纯 CSS 创作一个小球上台阶的动画
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/PBGJwL 可交互视频 ...
- Rreact Native 常见错误总结
1.invariant violation:expected a component class,got[object object] 创建自定义组件首字母要大写,否则会报错. ...
- style、 currentStyle、 runtimeStyle、getComputedStyle区别分析
1.obj.style只能获得内嵌样式(inline Style)就是写在Tag里面的,他访问不到那些链接的外部css和在head中用<style>声明的style. 所以必须认识到在那些 ...
- Effective C++ 条款04:确定对象被使用前已经先被初始化
规则一 永远在使用对象之前将它初始化 int x = 0; const char* text = "A C-style string"; double d; std:: cin & ...
- eclipse中的错误解决——The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
看看我们遇到的问题 解决问题
- CSS3 content属性学习
css3中出现了 ":before",":after"伪类, 你可以这样写: h1:after{ content:'h1后插入的文本'; ... } 这两个选择 ...
- 需要记忆的几个sql语句
链接查询: 1.查询两个表,在where中定义连接条件: select student.sno,sname,ssex,sage,sdept,cno,grade. from student,sc whe ...