zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    二测试组织
    如何编写测试计划
    C#三种字符串拼接方法的效率对比
    CSS内容溢出时,显示省略号
    JQuery文件上传控件Uploadify文档
    LINQ to Entities 不识别方法“Boolean Like(System.String, System.String)”,因此该方法无法转换为存储表达式。
    Linux 各目录的作用
    服务器注释事项
    资料:mnist.pkl.gz数据包的下载以及数据内容解释
    RockPaperScissorsLizardSpock Python实现
  • 原文地址:https://www.cnblogs.com/ZGQblogs/p/10672015.html
Copyright © 2011-2022 走看看