Contest Setting
题意:有n个题目,每个题目都有一个难度,从里面选出k个难度不同的题目。
思路:可以转换成01背包来求,把k看成背包空间,把个难度题目的数量看作物品,然后跑01背包即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=998244353;
int cnt[1005];
ll dp[1005];
int main(){
int n,k;
scanf("%d%d",&n,&k);
map<int,int>m;
memset(cnt,0,sizeof(cnt));
int x;
int pos=0;
for(int i=0;i<n;i++){
scanf("%d",&x);
if(m[x]==0)
m[x]=++pos;
cnt[m[x]]++;
}
dp[0]=1;
for(int i=1;i<=pos;i++){
for(int j=k;j>=1;j--){
dp[j]=(dp[j]+1ll*dp[j-1]*cnt[i]%mod)%mod;
}
}
printf("%lld\n",dp[k]);
}