PAT (Advanced Level) 1045. Favorite Color Stripe (30)
最长公共子序列变形。
#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)的更多相关文章
- 【PAT甲级】1045 Favorite Color Stripe (30 分)(DP)
题意: 输入一个正整数N(<=200),代表颜色总数,接下来输入一个正整数M(<=200),代表喜爱的颜色数量,接着输入M个正整数表示喜爱颜色的编号(同一颜色不会出现两次),接下来输入一个 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 【PAT Advanced Level】1004. Counting Leaves (30)
利用广度优先搜索,找出每层的叶子节点的个数. #include <iostream> #include <vector> #include <queue> #inc ...
- PAT (Advanced Level) 1095. Cars on Campus (30)
模拟题.仔细一些即可. #include<cstdio> #include<cstring> #include<cmath> #include<algorit ...
随机推荐
- 编辑器phpstrom的快捷键修改
file->setting-->查找 keymap -->查找 format 格式化代码 ctrl+alt +L appearance-->外观-->显示行号
- Java-if 嵌套结构
import java.util.Scanner; public class ifs{ public static void main(String args[]){ Scanner in=new S ...
- iOS中静态库-.a文件生成和使用
最近在使用使用一个网上的Demo的时候. 出现另一令人烦恼的问题 . 就是它里面有嵌套的工程. 如下图所示. 工程里面还嵌套有一个工程. 真的是让人煞费苦心 …其实这个问题看起来并不是很难, 如果是一 ...
- bingo 跨action异步获取参数
html(定时器模拟异步) <script> setTimeout(function(){ window.teacInfo = {a:1,b:2}; },2000);</script ...
- SB淘宝api的奇葩问题! 一则服务器无法访问淘宝api
<?xml version="1.0" encoding="utf-8" ?><error_response><code>3 ...
- /etc/rc.local 与 /etc/init.d Linux 开机自动运行程序
1. /etc/rc.local 这是使用者自订开机启动程序,把需要开机自动运行的程序写在这个脚本里 --------引用---------------------- 在完成 run level 3 ...
- servlet容器开发要点
v1 是一个http服务器. v2 是一个servlet容器, 可以提供servlet的服务. => 动态load servlet字节码,并运行它( 按生命周期). servlet容器它来 ...
- Dreamweaver使用过程的小技巧
在用Dreamweaver中制作网站的过程中,经常会遇到这样的问题,我们要修改一些属性类的标签,如<a href="abc/def.html">,如果我们要把href= ...
- layer属性
键: 值 描述 下表的属性都是默认值,您可在调用时按需重新配置,他们可帮助你实现各式各样的风格.如是调用: $.layer({键: 值, 键: 值, -}); type: 0 层的类型.0:信息框(默 ...
- Block 实现 浅析
前言 这里 有关于 block 的 5 道测试题,建议你阅读本文之前先做一下测试. 先介绍一下什么是闭包.在 wikipedia 上,闭包的定义) 是: In programming language ...