82ptsWA求助
查看原帖
82ptsWA求助
1074084
asd890123楼主2025/8/29 18:08

RT,WA了倒数第二个和倒数第四个点,WA代码:

#include<bits/stdc++.h>
const int N = 5000 + 5;
int a[N],dp[N],cnt[N];
int main(){
    std::cin.tie(0)->sync_with_stdio(0);
    int n;std::cin >> n;
    for (int i = 1;i <= n;i++) std::cin >> a[i];
    int ans = 0,ans2 = 0;
    for (int i = 1;i <= n;i++){
        for (int j = 1;j < i;j++)
            if (a[j] > a[i])
                dp[i] = std::max(dp[i],dp[j]);
        std::set<int> st;
        for (int j = 1;j < i;j++)
            if (a[j] > a[i] && dp[j] == dp[i]){
                int tmp = st.size();
                st.insert(a[j]);
                if (st.size() > tmp) cnt[i] += cnt[j];
            }
        ++dp[i];cnt[i] = std::max(cnt[i],1);
        ans = std::max(ans,dp[i]);
    }
    std::set<int> st;
    for (int i = 1;i <= n;i++)
        if (dp[i] == ans){
            int tmp = st.size();
            st.insert(a[i]);
            if (st.size() > tmp) ans2 += cnt[i];
        }
    std::cout << ans << ' ' << ans2 << '\n';
    return 0;
}
2025/8/29 18:08
加载中...