P14364 [CSP-S 2025] 员工招聘
dream_NOI
·
·
题解
题意:
# 分析1:
我们尝试暴力去枚举应聘顺序,再模拟计数即可得到答案
### 提醒:
注意到循环,若应聘人数已经到达$m$,即已经符合条件,直接跳出
## 代码:
```c++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int maxn = 510;
int n,m,c[maxn],p[maxn];
char s[maxn];
ll ans;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>s[i];
}
for(int i=1;i<=n;i++){
cin>>c[i];
p[i]=i;
}
do{
ll tg=0,wtg=0;
for(int i=1;i<=n;i++){
if(tg==m){
break;
}
if(s[i]=='1'){
if(wtg<c[p[i]]){
tg++;
}else{
wtg++;
}
}else{
wtg++;
}
}
if(tg==m){
ans=(ans+1)%mod;
}
}while(next_permutation(p+1,p+1+n));
cout<<ans;
return 0;
}
```
# 分析2:
## 代码:
```c++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int maxn = 510;
int n,m,c[maxn],p[maxn];
char s[maxn];
ll ans,tj[maxn],refuse[maxn],C[maxn],dp[maxn][maxn][maxn];
int main(){
cin>>n>>m;
C[0]=1;
for(int i=1;i<=n;i++){
C[i]=(C[i-1]*i)%mod;
}
int tg=0;
for(int i=1;i<=n;i++){
cin>>s[i];
if(s[i]=='1'){
tg++;
refuse[tg]=i-tg;
}
}
if(tg==0){
cout<<0;
return 0;
}
for(int i=1;i<=n;i++){
cin>>c[i];
tj[c[i]]++;
}
for(int i=1;i<=n;i++){
tj[i]=tj[i]+tj[i-1];
}
dp[0][0][0]=1;
for(int i=1;i<=tg;i++){
for(int x=0;x<i;x++){
for(int y=0;x+y<i;y++){
dp[i][x+1][y]=(dp[i][x+1][y]+1ll*dp[i-1][x][y]*max(tj[refuse[i]+x]-x-y,0ll)%mod)%mod;
dp[i][x][y+1]=(dp[i][x][y+1]+1ll*dp[i-1][x][y]*max(tj[refuse[i]+x]-x-y,0ll)%mod)%mod;
dp[i][x][y]=(dp[i][x][y]+dp[i-1][x][y]%mod)%mod;
}
}
}
for(int x=0;x<=tg-m;x++){
for(int y=0;x+y<=tg;y++){
ans=(ans+(y&1?mod-1:1)*dp[tg][x][y]%mod*C[n-x-y]%mod)%mod;
}
}
cout<<ans;
return 0;
}
```