guimei121212 @ 2024-10-14 22:39:30
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> a(n+1),dp(n+1,0);
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
if(!a[j-1]<a[j]){
int m=dp[1];
int t=i;
for(int j=2;j<=i;j++){
m=max(m,dp[j]);
if(m==dp[j]){
t=j;
}
}
if(a[t]<=a[i+1]){
dp[i]=m+1;
}else{
dp[i]=dp[i-1];
}
break;
}
dp[i]=dp[i-1]+1;
}
}
cout<<dp[n];
}
by sundingjia @ 2024-10-14 22:51:05
重复定义两个j+三重循环好玩吗?!
by xywuyu @ 2024-10-15 19:15:03
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,j,k,b[20001][3],l;
cin>>n;
for (int i=1;i<=n;i++)
{
cin>>b[i][1];
b[i][2]=1;
}
for (int i=n-1;i>=1;i--)
{
l=0;k=0;
for (int j=i+1;j<=n;j++)
{
if (b[j][1]>=b[i][1]&&b[j][2]>l)
{
l=b[j][2];
}
}
if (l>0)
{
b[i][2]=l+1;
}
}
k=1;
for (int j=1;j<=n;j++)
{
if (b[j][2]>b[k][2])k=j;
}
cout<<b[k][2];
return 0;
}
by wang_ze_xvan @ 2024-10-15 20:54:05
输出的是dp[1-n]的最大值,不是dp[n]
by guimei121212 @ 2024-10-17 22:13:32
@sundingjia 。。我好像没看到。。。
by guimei121212 @ 2024-10-17 22:14:24
@wang_ze_xvan ???
by wang_ze_xvan @ 2024-10-18 20:56:39
@guimei121212 输出的是dp[1]~dp[n]之间的最大值
by ljk6666 @ 2024-10-23 20:46:55
@guimei121212 这道题只能第一一个最长的变量,每次去统计
by guimei121212 @ 2024-10-23 21:22:58
@ljk6666 thank you