40求调(AC互关)

B3637 最长上升子序列

lsd110504 @ 2024-10-12 16:20:44

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n+1],c[n+1];
    memset(c,0,sizeof(c));
    int ans=0,cmp=0;
    c[1]=1;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        for(int j=i-1;j>=1;j--)
        {
            if(a[j]<a[i]&&c[j]>cmp){
                cmp=c[j];
                c[i]=c[j]+1;
                ans=max(ans,c[i]);
            }
            else

                continue;
        } 
        cmp=0;
    }
    cout<<ans;
    return 0;
} 

by lsrsrl @ 2024-10-12 16:24:32

#include <bits/stdc++.h>

using namespace std;

int req[5005];
int a[5005];
int main() {
    int n, ans = 0;
    cin >> n;
    for (int i = 0; i < n; i ++)
        cin >> req[i];
    req[n] = INT_MAX;
    for (int i = n - 1; i >= 0; i--){
        for (int j = i + 1; j <= n; j++)
            if (req[i] < req[j])
                a[i] = max (a[j] + 1, a[i]);
        ans = max (ans, a[i]);
    }
    cout << ans;
    return 0;
}

@lsd110504


by lsrsrl @ 2024-10-12 16:24:50

关注吧


by lsd110504 @ 2024-10-12 16:27:33

@lsrsrl 改一下我的吧,求求了


by lsrsrl @ 2024-10-12 16:30:48

你直接按照题解的模拟就行了,我也是这么做的


by lsd110504 @ 2024-10-12 16:32:30

? 不想看题解才在这里问啊


by ccch1ennn @ 2024-10-12 16:37:27

@lsd110504 数组什么的还是放在主函数外面定义比较好,不然会有一堆奇奇怪怪的问题


by hepp @ 2024-10-12 16:37:34

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n+1],c[n+1];
    int ans=0,cmp=0;
    for(int i=1;i<=n;i++)
    {
        c[i]=1;
        cin>>a[i];
        for(int j=i-1;j>=1;j--)
        {
            if(a[j]<a[i]&&c[j]>cmp){
                cmp=c[j];
                c[i]=c[j]+1;
                ans=max(ans,c[i]);
            }
            else
                continue;
        } 
        cmp=0;
    }
    cout<<ans;
    return 0;
} 

@lsd110504


by hepp @ 2024-10-12 16:38:04

问题是任何一个点都有可能成为起点


by lsd110504 @ 2024-10-12 16:41:14

@hepp 谢 谢! @lsrsrl @ccch1ennn 谢谢; 已过 互关互关


by ccch1ennn @ 2024-10-12 16:42:12

#include <bits/stdc++.h>
using namespace std;
int a[5000+1],c[5000+1];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) c[i]=1;
    int ans=0,cmp=0;
    //cout<<c[1]<<" ";
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        for(int j=1;j<i;j++)
        {
            if(a[j]<a[i]&&c[j]>cmp){
                cmp=c[j];
                c[i]=c[j]+1;
                ans=max(ans,c[i]);
            }
            //cout<<ans;
        } 
        cmp=0;
    }
    cout<<ans;
    return 0;
} 

来晚力()


| 下一页