当前位置:网站首页>Pat grade a 1045 favorite color stripe
Pat grade a 1045 favorite color stripe
2022-07-26 16:12:00 【IX. is it a non random title】
Own written content ,dynamic programming, Use the label to rise
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<bits/stdc++.h>
using namespace std;
int main(void){
int i, j, k, m, n, h, maxnum = -99999999, cnt;
cin>>m;
cin>>n;
vector<int> v, v0, v00;
set<int> st;
set<int>::iterator it;
map<int, int> mp;
v.resize(n);
for(i = 0; i < n; i++){
cin>>k;
v[i] = k;
st.insert(k);
mp[k] = i;
}
cin>>n;
h = -999;
cnt = 0;
for(i = 0; i < n; i++){
cin>>k;
it = st.find(k);
if(it!=st.end()){
if(h!=k){
v0.push_back(k);
h = k;
if(i!=0) v00.push_back(cnt);
cnt = 1;
}else{
cnt++;
}
}
}
v00.push_back(cnt);
vector<int> vtr, vtr0;
int dp[10001];
for(i = 0; i < v0.size(); i++){
dp[i] = v00[i];
for(j = 0; j < i; j++){
if(mp[v0[i]] > mp[v0[j]]){
dp[i] = max(dp[i], (dp[j] + v00[i]));
}
}
maxnum = max(maxnum, dp[i]);
}
printf("%d", maxnum);
return 0;
}Refer to others
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<bits/stdc++.h>
using namespace std;
int main(void){
int i, j, k, m, n, h=0, maxnum = -99999999;
cin>>m;
cin>>n;
int book[201], a[10001], dp[10001];
memset((void *)book, 0, sizeof(int)*201);
memset((void *)a, 0, sizeof(int)*10001);
memset((void *)dp, 0, sizeof(int)*10001);
for(i = 1; i <= n; i++){
cin>>k;
book[k] = i;
}
cin>>n;
for(i = 0; i < n; i++){
cin>>k;
if(book[k] >= 1){
a[h++] = book[k];
}
}
for(i = 0; i <= h; i++){
dp[i] = 1;
for(j = 0; j < i; j++){
if(a[i] >= a[j]){
dp[i] = max(dp[i], dp[j] + 1);
}
}
maxnum = max(maxnum, dp[i]);
}
printf("%d", maxnum);
return 0;
}边栏推荐
- [physical simulation] ultra simple shape matching simulates rigid body motion
- bucher齿轮泵QX81-400R301
- [tool sharing] automatic generation of file directory structure tool mddir
- 辨析 Ruby 中的 Method 与 Proc
- 什么是GPIO,它有什么用
- Google Earth Engine——MERRA-2 M2T1NXAER:1980-2022年气溶胶逐日数据集
- spark-streaming状态流之mapWithState
- Finally, someone explained the red blue confrontation clearly
- ZABBIX 6.2.0 deployment
- 【万字长文】使用 LSM-Tree 思想基于.Net 6.0 C# 实现 KV 数据库(案例版)
猜你喜欢

Mapwithstate of spark streaming state flow

Google Earth engine - merra-2 m2t1nxaer: aerosol daily data set from 1980 to 2022

Finally, someone explained the red blue confrontation clearly

DELTA控制器RMC200

PAT甲级 1044 Shopping in Mars
.net get injection object manually

This article explains in detail the discovery and processing of bigkey and hotkey in redis
FTP protocol

如何通过ETL调度工具 TASKCTL 使用作业插件类型调用 kettle作业?

教大模型自己跳过“无用”层,推理速度×3性能不变,谷歌MIT这个新方法火了...
随机推荐
Development and implementation of campus epidemic prevention and control management system based on SSM
换把人体工学椅,缓解久坐写代码的老腰吧~
朋友圈如何测试(思维导图)
Build resume editor based on Nocode
理解卷积神经网络中的权值共享
js 对数组操作的 API 总结
Is CICC Fortune Securities safe? How long does it take to open an account
【万字长文】使用 LSM-Tree 思想基于.Net 6.0 C# 实现 KV 数据库(案例版)
测试用例千万不能随便,记录由一个测试用例异常引起的思考
剑指offer专项突击版第11天
基于NoCode构建简历编辑器
潘多拉 IOT 开发板学习(RT-Thread)—— 实验17 ESP8266 实验(学习笔记)
操作系统迁移实战之在openEuler上部署MySQL数据库
2021年软件测试工具趋势
Bugku login1
FTP protocol
技术风向标 | 云原生技术架构成熟度模型解读
请问一下各位大佬,mysql-cdc建表如何指定表的字符集呢,在官网没找到相应的连接器参数。我读一个
Google Earth Engine——MERRA-2 M2T1NXAER:1980-2022年气溶胶逐日数据集
2022年最新西藏建筑施工架子工(建筑特种作业)模拟考试试题及答案