当前位置:网站首页>F - Two Exam(AtCoder Beginner Contest 238)

F - Two Exam(AtCoder Beginner Contest 238)

2022-07-05 05:31:00 solemntee

 Insert picture description here First of all, in accordance with the P P P Attribute sort owner , according to P P P Select people in ascending order of attributes , You only need to consider Q Q Q Property size relationship .
set up D P DP DP Status as d p [ i ] [ j ] [ k ] dp[i][j][k] dp[i][j][k]
Before presentation i i i Personal choice j j j individual , The smallest of them has not been selected Q Q Q The attribute is k k k The number of solutions
Consider the i + 1 i+1 i+1 Choose or not
Such as fruit k > The first i individual people Of Q Belong to sex d p [ i ] [ j + 1 ] [ k ] = ( d p [ i ] [ j + 1 ] [ k ] + d p [ i − 1 ] [ j ] [ k ] ) no be d p [ i ] [ j ] [ m i n ( k , The first i individual people Of Q Belong to sex ) ] = ( d p [ i ] [ j ] [ m i n ( k , The first i individual people Of Q Belong to sex ) ] + d p [ i − 1 ] [ j ] [ k ] ) If k> The first i Individual Q attribute \\dp[i][j+1][k]=(dp[i][j+1][k]+dp[i-1][j][k])\\ otherwise \\dp[i][j][min(k, The first i Individual Q attribute )]=(dp[i][j][min(k, The first i Individual Q attribute )]+dp[i-1][j][k]) Such as fruit k> The first i individual people Of Q Belong to sex dp[i][j+1][k]=(dp[i][j+1][k]+dp[i1][j][k]) no be dp[i][j][min(k, The first i individual people Of Q Belong to sex )]=(dp[i][j][min(k, The first i individual people Of Q Belong to sex )]+dp[i1][j][k])

#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct Stu
{
    
    int p,q;
    bool operator <(const Stu &ths)const
    {
    
        return p<ths.p;
    }
}stu[305];
int dp[305][305][305];// front i individual , Yes j individual , The smallest one not selected is k Number of alternatives 
const int mod=998244353;
int main()
{
    
    int n,K;
    scanf("%d%d",&n,&K);
    for(int i=1;i<=n;i++)scanf("%d",&stu[i].p);
    for(int i=1;i<=n;i++)scanf("%d",&stu[i].q);
    sort(stu+1,stu+1+n);
    dp[0][0][n+1]=1;
    for(int i=1;i<=n;i++)
    {
    
        for(int j=0;j<=i-1;j++)
        {
    
            for(int k=1;k<=n+1;k++)
            {
    
                dp[i][j][min(k,stu[i].q)]=(dp[i][j][min(k,stu[i].q)]+dp[i-1][j][k])%mod;
                if(k>stu[i].q)dp[i][j+1][k]=(dp[i][j+1][k]+dp[i-1][j][k])%mod;
            }

        }
// for(int j=0;j<=i;j++)
// for(int k=1;k<=n+1;k++)printf("dp[%d][%d][%d]=%d\n",i,j,k,dp[i][j][k]);
    }
    ll ans=0;
    for(int i=1;i<=301;i++)ans=(ans+dp[n][K][i])%mod;
    printf("%lld",ans);
    return 0;
}

原网站

版权声明
本文为[solemntee]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140621452857.html