最长公共子序列变形。

#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. C#中Bitmap类 对图像の操作 可检测图片完整性

    try { Bitmap bm = new Bitmap(pics[ip]); BitmapToBytes(bm).Reverse().Take(2); } catch (Exception ex) ...

  2. 辨别 ShopEX Ecshop

    御剑可以识别ShopEX 或者 Ecshop 特征 ShopEX : 蓝色的icon js里有很多Cookie. <link rel="stylesheet" href=&q ...

  3. servlet第3讲(中集)----同一用户的不同页面共享数据

    5.session 5.1session概述 5.2.session应用举例  

  4. MJExtension的使用

    1. Plist → 模型数组 控制器中引用#import "MJExtension.h" 模型数组 = [模型类名 objectArrayWithFilename:@" ...

  5. easyui 动态渲染

    $.parser.parse   这个 $("div[data-easyuisrc]").html(function () { var url = $(this).attr(&qu ...

  6. htop安装步骤【原创】

    htop安装步骤 下载:http://hisham.hm/htop/releases/ [root@hchtest2 ~]# tar zxvf htop-2.0.2.tar.gz [root@hcht ...

  7. 【C#】HTTP请求GET,POST(远程证书失效)

    HTTP定义了与服务器交互的不同方法,基本方法有GET,POST,PUT,DELETE,分别对于查,该,增,删.一般情况下我们只用到GET和POST,其他两种都也可以用GET和POST来实现,很多浏览 ...

  8. wpf CollectionViewSource与ListBox的折叠、分组显示,及输入关键字 Filter的筛选

    在wpf中虽然ObservableCollection<T>作为ListBox的Itemsource,很好,很强大!但是CollectionViewSource与ListBox才是天作之合 ...

  9. 四种xml的解析方式

    这篇文章是我上网找资料,加上自己总结了一些而得 资料来源: http://www.cnblogs.com/allenzheng/archive/2012/12/01/2797196.html http ...

  10. springmvc 关于controller的字符编码

    在使用springMVC框架构建web应用,客户端常会请求字符串.整型.json等格式的数据,通常使用@ResponseBody注解使 controller回应相应的数据而不是去渲染某个页面.如果请求 ...