最长公共子序列变形。

#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. leetcode83,删除有序链表中的重复元素

    Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...

  2. Chapter 1 Mr.Sherlock Holmes

    I took my degree of Doctor of Medicine in the University of London, and proceeded to Netley to go th ...

  3. Web开发人员不要错过的60款用户界面设计工具(下)

    41. Snipplr 包含最新的脚本和jQuery技术资源库. 42. Midori Midori是一个超轻量级的JavaScript框架,可使用CSS选择器快速访问页面上对应的元素. 43. ro ...

  4. 微信支付坑:url未注册

    微信支付,报:url未注册 页面URL未注册 支付授权目录 这里很重要我就是在这里折腾了很久.怎么设置呢,首先要看你支付的当前页面URL 比如是:http://www.taidupa.com/wxpa ...

  5. nginx 安装三方包重新编译

    sudo -sapt-get source nginxapt-get build-dep nginxwget 'https://github.com/agentzh/chunkin-nginx-mod ...

  6. linux下如何开放80端口

    linux清屏命令:clear linux版本:CentOS6.5 1.开启80端口命令:/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT2.保存 ...

  7. webstorm比dreamweaver强大的地方 转

    比dw强大的地方有: . 对js的开发有长足的支持,那些自动提示,代码主题,调试之类的我就不说了,主要是对流行技术的支持,比如Node.js,less,sass,jq,ext,prototype等框架 ...

  8. 转 Problem: AnyConnect was not able to establish a connection to the specified secu

    不多说直接上问题,在点击连接时,也是能正常连接上输入密码,在输出用户名密码后 连接后,会出现: problem:anyconnect was net able to establish a conne ...

  9. 2.1 工具使用:xmind

    概念 心智图,又称脑图.思维导图.灵感触发图.概念地图或思维地图,是一种图像式思维的工具与及一种利用图像式思考辅助工具来表达思维的工具. 详细的可以查看这里(维基百科)还有这里(百度百科) 用了思维导 ...

  10. 超棒的自定义超酷滚动条jQuery插件 - Perfect Scrollbar

    可能大家厌倦了千篇一律的页面滚动条,如果你希望能够设计出与众不同的页面UI设计的话,Perfect ScrollBar可能就是你寻找的解决方案. 这个滚动条来自于一个个人项目,一个简单但是非常棒的滚动 ...