-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOrderlyString.cpp
More file actions
39 lines (34 loc) · 808 Bytes
/
Copy pathOrderlyString.cpp
File metadata and controls
39 lines (34 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<bits/stdc++.h>
using namespace std;
class OrderlyString{
public:
int dp[250];
int longestLength(string s){
memset(dp,-1,sizeof(dp));
dp[0]=1;
for(int i=1;i<s.size();i++){
dp[i]=1;
for(int j=0;j<i;j++){
if(s[j]<=s[i]){
dp[i]=max(dp[i],1+dp[j]);
}
}
}
int ans=-1;
for(int i=0;i<s.size();i++){
if(ans<dp[i]){
ans=dp[i];
}
}
// int Ans=(int)s.size()-ans;
return ans;
}
};
int32_t main(){
ios::sync_with_stdio(false);
OrderlyString O;
cout<<O.longestLength("ABCDEFG")<<"\n";
cout<<O.longestLength("GFEDCBA")<<"\n";
cout<<O.longestLength("ACBB")<<"\n";
return 0;
}