写出完整的c++代码
时间: 2023-08-07 19:15:13 浏览: 214
好的,以下是完整的C++代码:
```cpp
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int longest_increasing_subsequence(string s) {
int n = s.length();
int dp[n];
fill(dp, dp + n, 1);
for (int i = 1; i < n; i++) {
for (int j = 0; j < i; j++) {
if (s[j] < s[i]) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
}
return *max_element(dp, dp + n);
}
int main() {
int n;
cin >> n;
while (n--) {
string s;
cin >> s;
cout << longest_increasing_subsequence(s) << endl;
}
return 0;
}
```
输入示例:
```
3
aaa
ababc
abklmncdefg
```
输出示例:
```
1
3
7
```
阅读全文