比赛 NOIP2023模拟赛2 评测结果 MMMMMMMMMMMMMMMM
题目名称 魔药 最终得分 0
用户昵称 ┭┮﹏┭┮ 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2023-11-14 12:56:22
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long N = 4e3+10,mod = 1e9+7;
int n,m,k;
ll s[1000010] = {0,1},f[N][N],ans,g[N][N];
char c[1000010];
long long C(int x,int y){
    return s[x] / s[x-y] / s[y] % mod;
}
int u[1000010];
bool check(){
    int s = 1;
    for(int i = 2;i <= n;i++)
        if(u[i] != u[i-1])s++;
    return (s == m);
}
void sou(int x,int cnt){
    if(x == n+1){
        if(cnt == k)
            if(check()){
                ans = (ans + 1) % mod;
//                for(int i = 1;i <= n;i++)cout<<u[i]<<' ';
//                cout<<endl;
            }
        return;
    }
    u[x] = 1;
    sou(x+1,cnt+1);
    u[x] = 0;
    sou(x+1,cnt);
}
int main(){
    freopen("sleeping.in","r",stdin);
    freopen("sleeping.out","w",stdout);
    scanf("%lld%lld%s",&n,&m,c+1);
    for(int i = 1;i <= n;i++)if(c[i] == '1')k++;
    for(int i = 2;i <= n;i++)s[i] = s[i-1] * i % mod;
    if(n <= 16){
        sou(1,0);
        long long s = C(n,m) - ans;
        if(s < 0)s += mod;
        printf("%lld %lld\n",ans,s);
        return 0;
    }
    if(m > n){
        printf("0 %lld\n",C(n,k));
        return 0;
    }
    for(int i = 1;i <= n;i++){
        f[i][1] = 1;
        g[i][1] = f[i][1] + g[i-1][1];
    }
    for(int i = 2;i <= max(k,m);i++)
        for(int j = 1;j <= min(i,m);j++){
//            for(int l = 1;l <= i;l++)
//                f[i][j] += f[i-l][j-1];
            f[i][j] += g[i-1][j-1];
            g[i][j] = f[i][j] + g[i-1][j];
        }
    if(m % 2 == 0)ans = 2 * f[k][m/2] * f[n-k][m/2] % mod;
    else ans = (f[k][m/2] * f[n-k][m/2+1]) % mod + (f[k][m/2+1] * f[n-k][m/2]) % mod;
//    cout<<ans<<endl;
    long long s = C(n,m) - ans;
    if(s < 0)s += mod;
    printf("%lld %lld\n",ans,s);
    
    return 0;
    
}