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> ...
随机推荐
- eclipse中自动加载源码的方法
1.选中项目右键properties--java build path--Libraries--Add External class Folder 找到项目将项目添加进去 2.然后就是这样 3.OK
- 认识shiro
shiro是安全(权限)框架,不仅可以在javase中也可以在javaee中 shiro可以完成认证.授权.加密.会话管理,与web进行集成.缓存等. Authentication:身份认证/登录,验 ...
- dbml 注意事项
1,修改dbml中的字段,需要修改2个地方
- NFS 安装、管理
NFS简介 NFS允许一个系统在网络上与他人共享目录和文件.通过使用NFS,用户和程序可以像访问本地文件一样访问远程系统上的文件. 安装NFS 服务端安装 NFS安装包:nfs-utils-lib.i ...
- Gnostice PDFtoolkit VCL的安装
Installation and Uninstallation For New Users Close all open applications including the IDE. Run the ...
- quartz(4)--quartz.properties文件
Quartz有一个叫做quartz.properties的配置文件,它允许你修改框架运行时环境.缺省是使用Quartz.jar里面的quartz.properties文件.当然你应该创建一个quart ...
- No module named yum
升级python之后,执行yum的时候可能出现错误,类似: There was a problem importing one of the Python modulesrequired to run ...
- AppWidget源码分析---updateAppWidget过程分析
转[原文] 前面一篇文章,分析了AppWidgetProvider和RemoteView的源码,从中我们可以知道它们的实现原理,AppWidgetProvider是一个BroadcastReceive ...
- throws和throw的用法例子以及检测和非检查异常
throws E1,E2,E3 只是告诉程序这个方法可能会抛出这些个异常,方法的调用者可能要处理这些异常.而这些异常E1,E2,E3可能是该函数体产生的. 而throw是明确之处这个地方要抛出这个异常 ...
- 使用Mybatis时报错Invalid bound statement (not found):
使用逆向工程时生成的.xml文件在conf目录下,而使用查询方法时,无法在dao包下找到xml文件,所以报错. 测试代码如下所示: @Test public void testSimple() thr ...