Gym - 101982C Contest Setting (动态规划)

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\n",dp[sz][k]);

}
View Code

 

转载于:https://www.cnblogs.com/ZGQblogs/p/10672015.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值