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
  • 相关阅读:
    递推 hdu 1396
    递推 hdu 3411
    Eclipse中git上如何把自己的分支保存到远端
    api-gateway-engine知识点(1)
    Java知识点ArrayList
    如何利用VMware安装XP系统
    IOP知识点(1)
    Eclipse如何导入DemoWeb.rar
    mysql忘记root密码
    实习培训——Java多线程(9)
  • 原文地址:https://www.cnblogs.com/ZGQblogs/p/10672015.html
Copyright © 2011-2022 走看看