• Gym


    A group of contest writers have written n problems and want to use k of them in an upcoming contest. Each problem has a difficulty level. A contest is valid if all of its k problems have different difficulty levels.

    Compute how many distinct valid contests the contest writers can produce. Two contests are distinct if and only if there exists some problem present in one contest but not present in the other.

    Print the result modulo 998,244,353.

    Input

    The first line of input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 1000)

    The next line contains n space-separated integers representing the difficulty levels. The difficulty levels are between 1 and 109 (inclusive).

    Output

    Print the number of distinct contests possible, modulo 998,244,353.

    Sample Input

    5 2

    1 2 3 4 5

    Sample  Output

    10

    题意:

    选出k个难度不同的题,问有几种选法。

    思路:

    dp[i][j]表示从i种不同的题中选出j个不同的题的方法数。

    当前题选的话,方法数是dp[i-1][j-1]*(当前难度题的个数)

    当前题不选的话,方法数是dp[i-1][j].

    dp[i][j]就是二者之和。

    #include<iostream>
    #include<algorithm>
    #include<vector>
    #include<stack>
    #include<queue>
    #include<map>
    #include<set>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<ctime>
    #define fuck(x) cout<<#x<<" = "<<x<<endl;
    #define ls (t<<1)
    #define rs ((t<<1)+1)
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    const int maxn = 100086;
    const int inf = 2.1e9;
    const ll Inf = 999999999999999999;
    const int mod = 998244353;
    const double eps = 1e-6;
    map<int,int>mp;
    ll dp[1004][1005];
    int main()
    {
        int n,k;
        scanf("%d%d",&n,&k);
        ll ans=1;
        ll num=1;
        for(int i=1;i<=n;i++){
            int x;
            scanf("%d",&x);
            mp[x]++;
        }
        map<int,int>::iterator it=mp.begin();
        int sz=mp.size();
        for(int i=0;i<=sz;i++){
            dp[i][0]=1;
        }
        for(int i=1;i<=sz;i++){
            for(int j=k;j>=1;j--){
                dp[i][j]=dp[i-1][j]+dp[i-1][j-1]*(it->second);
                dp[i][j]%=mod;
            }
            it++;
        }
        printf("%lld
    ",dp[sz][k]);
    
    }
    View Code
  • 相关阅读:
    Unable to connect to web server 'IIS Express'(无法连接到Web服务器“IIS Express”)的解决方式-Jexus Manager
    temp_web
    使用Fluent配置表关系
    面试题链接记录
    面试题
    SQL语言基础
    .net core中DbProviderFactories配置问题
    Swagger UI in AspNetCore WebAPI
    JS实现国密算法SM2加密,后端Java解密
    Java读取磁盘指定扇区
  • 原文地址:https://www.cnblogs.com/ZGQblogs/p/10672015.html
Copyright © 2020-2023  润新知