当前位置:网站首页>Longest ascending subsequence model acwing 1010. Interceptor missile
Longest ascending subsequence model acwing 1010. Interceptor missile
2022-07-27 11:13:00 【T_ Y_ F666】
Longest ascending subsequence model AcWing 1010. Interceptor missile
Original link
AcWing 1010. Interceptor missile
Algorithm tags
DP linear DP Longest ascending subsequence
Ideas
Code
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 1005, INF = 0x3f3f3f3f;
// f1[i] Indicates the... At this time i The altitude of the last missile intercepted by the missile interception system
int f[N], f1[N], a[N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
vector<string> get(string str){
vector<string> res;
string word;
for (auto c: str){
if (c == ' '){
res.push_back(word);
word = "";
}
else word += c;
}
res.push_back(word);
return res;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
getline(cin, s);
vector<string> v=get(s);
int ans=0, cnt=0, n=v.size();// cnt Represents the length of the existing subsequence
rep(i, 0, n){
a[i]=stoi(v[i]);
}
// With i Ending descent sequence
rep(i, 0, n){
f[i]=1;
rep(j, 0, i){
if(a[j]>=a[i]){
f[i]=max(f[i], f[j]+1);
}
}
ans=max(ans, f[i]);
int k=0;
while(k<cnt&&f1[k]<a[i]){
k++;
}
// a[i] Create a new interception system
if(k==cnt){
f1[cnt++]=a[i];
}
// a[i] Be the first k The last Missile Altitude of the interceptor system
else{
f1[k]=a[i];
}
}
printf("%lld\n%lld\n", ans, cnt);
}
y Master code
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1010;
int n;
int h[N], f[N], q[N];
int main()
{
string line;
getline(cin, line);
stringstream ssin(line);
while (ssin >> h[n]) n ++ ;
int res = 0, cnt = 0;
for (int i = 0; i < n; i ++ )
{
f[i] = 1;
for (int j = 0; j < i; j ++ )
if (h[i] <= h[j])
f[i] = max(f[i], f[j] + 1);
res = max(res, f[i]);
int k = 0;
while (k < cnt && q[k] < h[i]) k ++ ;
if (k == cnt) q[cnt ++ ] = h[i];
else q[k] = h[i];
}
printf("%d\n", res);
printf("%d\n", cnt);
return 0;
}
tips
Read in processing
Input stream advanced syntax
string line;
getline(cin, line);
stringstream ssin(line);
while (ssin >> h[n]) n ++ ;
or
while (cin >> h[ ++ n]);
边栏推荐
- 深析C语言的灵魂 -- 指针
- What changes will metauniverse bring to the music industry in the trillion market?
- Regular form form judgment
- Application of 5g private network in smart medicine
- Sorry, you guys have something to deal with in the bank recently, which has been delayed
- Introduction to software vulnerability analysis (I)
- FAQs of "relay chain" and "dot" in Poka ecosystem
- 正则form表单判断
- Neural network learning notes
- Delete in MySQL: the difference between delete, drop and truncate
猜你喜欢

MySQL installation (RPM package)

Derive the detailed expansion of STO double center kinetic energy integral

How to assemble a registry

最长上升子序列模型 AcWing 482. 合唱队形

Derivation of the detailed expansion sto overlap integrals

Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached

迭代次数和熵之间关系的一个验证试验

15 design movie rental system

Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?

Use of beautifulsoup
随机推荐
Ansible
10 complete half of the questions
Substr and substring function usage in SQL
背包模型 AcWing 1022. 宠物小精灵之收服
Chengying, kangaroo cloud one-stop fully automated operation and maintenance steward, is officially open source
Error: image clipToBoundsAndScale, argument 'input'
荒野觅踪---寻找迭代次数
背包模型 AcWing 423. 采药
NFT leaderboard -nft real offer latest address: NFT leaderboard.com
8 find subsequences with a maximum length of K
Yonbuilder enables innovation, and the "golden keyboard Award" of the fourth UFIDA developer competition is open!
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
Use kaggle to run Li Hongyi's machine learning homework
深析C语言的灵魂 -- 指针
Shock simulation of engine mounting system transient modal dynamic analysis and response spectrum analysis
349两个数组的交集和01两数之和
JVM judges that the object is dead, and practices verify GC recycling
洛谷P1441 砝码称重
Compete for the key battle of stock users and help enterprises build a perfect labeling system - 01 live review
How to build a data index system is the most effective. It will take you a quick start from 0 to 1
