原题链接:
https://vjudge.net/problem/Gym-101982C
AC代码:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int INF = 0x3fffffff;
typedef long long ll;
void __init__()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
}
map<ll, ll> mp;
ll dp[1050][1050];
int main()
{
__init__();
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
mp[temp]++;
}
int siz = mp.size();
auto it = mp.begin();
memset(dp, 0, sizeof(dp));
for (int i = 0; i <= siz; i++)
{
dp[i][0] = 1;
}
for (int i = 1; i <= siz; i++)
{
for (int j = 1; j <= k; j++)
{
dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1] * it->second) % 998244353;
}
it++;
}
cout << dp[siz][k] << endl;
return 0;
}
动态规划、dp[i][j]表示当有i个类型的题时,选出j个题的方案数
dp[i][j]=dp[i-1][j]+dp[i-1][j-1]*(当前类型题的题数)