当前位置:网站首页>2021 CCPC Harbin B. magical subsequence (thinking question)
2021 CCPC Harbin B. magical subsequence (thinking question)
2022-07-04 21:21:00 【GHOSTANDBREAD】
Problem - B - Codeforces
Ideas :
From front to back, find the maximum length of the sum of two . It can be discontinuous , But it must be in the order from front to back . It can be found that the range of each number is [1,100], Not much , Is a breakthrough , The sum of two numbers sum The range is [2,200], The traverse sum In every case . When the number being traversed and the number appearing before are added together, it is equal to sum when ,res+=2, Then set the previous number to be unusable . If the sum of the numbers being traversed sum The difference has not appeared before , Then set the number to be usable , Continue traversing backwards .
Code :
#include<iostream>
#include<cstring>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int vis[205];
int n, maxn;
int main() {
scanf("%d", &n);
vector<int> a(n);
for(int i = 0; i < n; i ++) scanf("%d", &a[i]);
int maxn = -1;
for(int sum = 2; sum <= 200; sum ++) {
int res = 0;
memset(vis, 0, sizeof vis);
for(int i = 0; i < n; i ++) {
if(a[i] < sum) {
if(vis[sum - a[i]]) {
res += 2;
memset(vis, 0, sizeof vis);
} else {
vis[a[i]] = 1;
}
}
}
maxn = max(maxn, res);
}
printf("%d", maxn);
return 0;
}
边栏推荐
猜你喜欢
Y56. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (29)
HWiNFO硬件检测工具v7.26绿色版
华为ensp模拟器 给路由器配置DHCP
【服务器数据恢复】某品牌服务器存储raid5数据恢复案例
【1200. 最小絕對差】
每日一题-LeetCode556-下一个更大元素III-字符串-双指针-next_permutation
uniapp 富文本编辑器使用
shp数据制作3DTiles白膜
数十亿公民信息遭泄漏!公有云上的数据安全还有“救”吗?
Foxit pdf editor v10.1.8 green version
随机推荐
Solution of 5g unstable 5g signal often dropped in NetWare r7000 Merlin system
Actual combat simulation │ JWT login authentication
Redis:Redis配置文件相关配置、Redis的持久化
The concept and application of hash table
B站视频 声音很小——解决办法
网络命名空间
华为ensp模拟器 给路由器配置DHCP
Foxit pdf editor v10.1.8 green version
杰理之AD 系列 MIDI 功能说明【篇】
Embedded TC test case
网件r7000梅林系统虚拟内存创建失败,提示USB磁盘读写速度不满足要求解决办法,有需要创建虚拟内存吗??
redis发布订阅的使用
WGCNA分析基本教程总结
ApplicationContext 与 BeanFactory 区别(MS)
Day24: file system
CAD中能显示打印不显示
杰理之AD 系列 MIDI 功能说明【篇】
Hands on deep learning (III) -- convolutional neural network CNN
[observation] Lenovo: 3x (1+n) smart office solution, releasing the "multiplier effect" of office productivity
Introduction to pressure measurement of JMeter