LOADING

加载过慢请开启缓存,浏览器默认开启

daily 2

2023/7/10 daily

CF 1077F1

int main(){
    int n,k,x;
    cin>>n>>k>>x;
    vector<int>a(n+1);
    for(int i=1;i<=n;++i)cin>>a[i];
    vector<vector<ll>>dp(n+1,vector<ll>(n+1,-1e18));
    dp[0][0]=0;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=min(x,i);++j){
            for(int p=max(0,i-k);p<=i-1;++p){
                dp[i][j]=max(dp[i][j],dp[p][j-1]+a[i]);
            }
        }
    }
    ll ans=-1e18;
    for(int i=n;i>max(0,n-k);--i){
        ans=max(ans,dp[i][x]);
    }
    if(ans<0){
        cout<<-1<<'\n';
        return 0;
    }
    cout<<ans<<'\n';
}

CF 999F

map<int,int>card_cnt;
map<int,int>love_cnt;
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n*k;++i){
        int x;
        cin>>x;
        card_cnt[x]++;
    }
    for(int i=1;i<=n;++i){
        int x;
        cin>>x;
        love_cnt[x]++;
    }
    vector<int>h(k+1);
    for(int i=1;i<=k;++i)cin>>h[i];
    ll ans=0;
    for(auto& kk:card_cnt){
        vector<ll>dp(n*k+1);
        if(kk.second==0||love_cnt.find(kk.first)==love_cnt.end())continue;
        int num=kk.second;
        for(int i=1;i<=love_cnt[kk.first];++i){
            for(int j=kk.second;j>=1;--j){
                for(int t=0;t<=min(j,k);++t){
                    dp[j]=max(dp[j],dp[j-t]+h[t]);
                }
            }
        }
        ans+=dp[kk.second];
        kk.second=0;
    }
    cout<<ans<<'\n';
}