HihoCoder

来源:互联网 发布:好的南方二本院校知乎 编辑:程序博客网 时间:2024/06/06 12:31

#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>#include <bitset>#define INF 0x3f3f3f3f#define eps 1e-6#define PI 3.1415926#define mod 1000000007#define base 2333using namespace std;typedef long long LL;const int inf = 1e9;const int maxn = 5e4 + 10;const int maxx = 1e3 + 10;int t, n, k;LL c[110][110], pre[maxn][110], pp[maxn][110];char str[maxn];void init() {    memset(c, 0, sizeof(c));    for(int i = 0; i < 110; i++)        c[i][0] = c[i][i] = 1;    for(int i = 1; i < 110; i++) {        for(int j = 1; j < i; j++)            c[i][j] = (c[i-1][j-1]+c[i-1][j])%mod;    }    for(int i = 0; i < maxn; i++)        pre[i][0] = pp[i][0] = 1;}void solve() {    init();    scanf("%d", &t);    while(t--) {        scanf("%d%d%s", &n, &k, str+1);        for(int i = 1; i <= n; i++) {            pre[i][1] = (pre[i-1][1]+str[i]-'0')%mod;            for(int j = 2; j <= k; j++)                pre[i][j] = pre[i][j-1]*pre[i][1]%mod;        }        for(int i = 1; i <= n; i++) {            for(int j = 0; j <= k; j++)                pp[i][j] = (pp[i-1][j]+pre[i][j])%mod;        }        for(int i = 1; i <= n; i++) {            LL ans = 0;            for(int j = 0; j <= k; j++) {                if((k-j)%2 == 0)                    ans = (ans+c[k][j]*pre[i][j]%mod*pp[i-1][k-j]%mod+mod)%mod;                else                    ans = (ans-c[k][j]*pre[i][j]%mod*pp[i-1][k-j]%mod+mod)%mod;            }            if(i == n) printf("%lld\n", ans);            else printf("%lld ", ans);        }    }}int main() {    //srand(time(NULL));    //freopen("kingdom.in","r",stdin);    //freopen("kingdom.out","w",stdout);    solve();}


原创粉丝点击