最长公共子序列变形。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std; int n,M,L;
int a[],b[];
int dp[][]; int MAX(int a,int b,int c)
{
return max(a,max(b,c));
} int main()
{
scanf("%d",&n);
scanf("%d",&M); for(int i=;i<=M;i++) scanf("%d",&a[i]);
scanf("%d",&L); for(int i=;i<=L;i++) scanf("%d",&b[i]);
memset(dp,,sizeof dp);
for(int i=;i<=M;i++)
{
for(int j=;j<=L;j++)
{
if(a[i]==b[j]) dp[i][j]=MAX(dp[i-][j-],dp[i-][j],dp[i][j-])+;
else dp[i][j]=max(dp[i-][j],dp[i][j-]);
}
}
printf("%d\n",dp[M][L]);
return ;
}

PAT (Advanced Level) 1045. Favorite Color Stripe (30)的更多相关文章

  1. 【PAT甲级】1045 Favorite Color Stripe (30 分)(DP)

    题意: 输入一个正整数N(<=200),代表颜色总数,接下来输入一个正整数M(<=200),代表喜爱的颜色数量,接着输入M个正整数表示喜爱颜色的编号(同一颜色不会出现两次),接下来输入一个 ...

  2. PAT 甲级 1045 Favorite Color Stripe (30 分)(思维dp,最长有序子序列)

    1045 Favorite Color Stripe (30 分)   Eva is trying to make her own color stripe out of a given one. S ...

  3. 1045. Favorite Color Stripe (30) -LCS允许元素重复

    题目如下: Eva is trying to make her own color stripe out of a given one. She would like to keep only her ...

  4. 1045. Favorite Color Stripe (30) -LCS同意元素反复

    题目例如以下: Eva is trying to make her own color stripe out of a given one. She would like to keep only h ...

  5. 1045 Favorite Color Stripe (30)(30 分)

    Eva is trying to make her own color stripe out of a given one. She would like to keep only her favor ...

  6. 1045 Favorite Color Stripe (30)

    Eva is trying to make her own color stripe out of a given one. She would like to keep only her favor ...

  7. 1045 Favorite Color Stripe (30分)(简单dp)

    Eva is trying to make her own color stripe out of a given one. She would like to keep only her favor ...

  8. 【PAT Advanced Level】1004. Counting Leaves (30)

    利用广度优先搜索,找出每层的叶子节点的个数. #include <iostream> #include <vector> #include <queue> #inc ...

  9. PAT (Advanced Level) 1095. Cars on Campus (30)

    模拟题.仔细一些即可. #include<cstdio> #include<cstring> #include<cmath> #include<algorit ...

随机推荐

  1. MFC下DLL编程(图解)

    MFC下DLL编程(图解) DLL(Dynamic Link Library,动态链接库)是微软公司为Windows和OS/2操作系统设计一种供应用程序在运行时调用的共享函数库.DLL是应用程序的一种 ...

  2. mysql 注册登陆表单并且操纵元素

    <?php      error_reporting(E_ALL^E_DEPRECATED^E_NOTICE);    header("content-type:text/html;c ...

  3. hdu_5776_sum(前缀和维护)

    题目链接:hdu_5776_sum 题意: 给你一串数,问你是否有一个连续的子序列的和为m的倍数 题解: 维护一个前缀和%m的值,如果前缀和%m的值为0或者有两个前缀和%m的值相同,那么就有一个连续区 ...

  4. iOS长按选择

    确实,其实就是一个长按手势 + 图片二维码识别,原生SDK从8.0开始支持 /** *  从照片中直接识别二维码 *  @param qrCodeImage 带二维码的图片 *  @param myQ ...

  5. 17 个 tar 命令实用示例【转】

    Tar(Tape ARchive,磁带归档的缩写,LCTT 译注:最初设计用于将文件打包到磁带上,现在我们大都使用它来实现备份某个分区或者某些重要的目录)是类 Unix 系统中使用最广泛的命令,用于归 ...

  6. perl-cgi高级

    来源: http://www.cnblogs.com/itech/archive/2012/10/07/2714393.html 一 CGI.pm中的方法(routines)调用  1. CGI.pm ...

  7. mysql if then

    CREATE PROCEDURE userinfo_modify( IN id INT ,IN loginid INT ,IN levelid INT ,IN namestr VARCHAR(50) ...

  8. ComboBox绑定Dictionary做为数据源

    http://www.cnblogs.com/refresh/archive/2012/07/14/2591503.html https://msdn.microsoft.com/zh-cn/libr ...

  9. centos配置samba

    一.samba服务器的安装与配置 [root@localhost ~]# yum -y install samba samba-common samba-client        samba服务器所 ...

  10. linux 守护进程创建流程

    #include <sys/stat.h> #include <fcntl.h> /* Bit-mask values for 'flags' argument of beco ...