最长公共子序列变形。

#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. POJ 1062 昂贵的聘礼(dij+邻接矩阵)

    ( ̄▽ ̄)" #include<iostream> #include<cstdio> #include<cstring> #include<cstd ...

  2. print a float number with 3 digits following

    just use the java's printf function. It is like C's printf. System.out.printf("%.3f\n", x) ...

  3. 常见B2C网站购物车的设计

    对于大部分B2C网站来说,购物车是网站的咽喉之地,订单是白花花的银子,所有银子都必然流经购物车,购物车不能有失.优秀的购物车设计至少需要完成两项使命:一是方便用户多买货多掏银子:二是帮用户保管好待购的 ...

  4. ios网站

    www.diveinedu.cn/nav/index.html  

  5. Spring Security3实现,权限动态获取

    Spring Security3实现,权限动态获取 原文  http://blog.csdn.net/yangwei19680827/article/details/9359113 主题 网络安全Sp ...

  6. 给table加边框的两种方法

    <!DOCTYPE html><html><head><style>.a { border-spacing: 1px; background-color ...

  7. Java-List泛型的用处(能够使用传入泛型对象的方法)

    List<PageData> varList = setMealService.list(page); for(int i = 0;i < varList.size(); i++){ ...

  8. initWithFrame、initWithCoder、awakeFromNib的区别和调用次序 & UIViewController生命周期 查缺补漏

    当我们创建或者自定义一个UI控件时,就很可能会调用awakeFromNib.initWithCoder .initWithFrame这些方法.三者的具体区别如下: initWithFrame: 通过代 ...

  9. js数组总结

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  10. lucene特殊字符处理

    这是个郁闷的问题,今天遇到了,但在lucene中查询的关键字保护有特殊字符,譬如--,会出现如下异常: org.apache.lucene.queryParser.ParseException: Ca ...