[Dwango Programming Contest 6th C] Cookie Distribution

传送门

组合意义,妙啊(弱菜 swk 不会数数实锤了

考虑 \(\prod c_i\) 的组合意义,它代表每个孩子在他得到的饼干中选择一个拿出来,最终的方案数。

因此得到了一个几乎显然的 dp:

设 \(f_{i, j}\) 为前 \(i\) 天,有 \(j\) 个孩子已经 “选择了” 他的饼干的方案数。转移时枚举新增了 \(u\) 个孩子,则转移系数是一系列组合数,详见代码。

#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1100, K = 22, mod = 1e9 + 7;

int n, k, a[K];
ll f[K][N], comb[N][N];

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

inline ll addMod(ll a, ll b) {
    return (a += b) >= mod ? a - mod : a;
}

int main() {
    read(n), read(k);
    for (R int i = 1; i <= k; ++i) read(a[i]);
    for (R int i = 0; i <= n; ++i) {
        comb[i][0] = 1;
        for (R int j = 1; j <= i; ++j)
            comb[i][j] = addMod(comb[i - 1][j - 1], comb[i - 1][j]);
    }
    f[0][0] = 1;
    for (R int i = 1; i <= k; ++i)
        for (R int j = 0; j <= n; ++j)
            for (R int l = max(0, j - a[i]); l <= j; ++l)
                f[i][j] = (f[i][j] + f[i - 1][l] * comb[n - l][j - l] % mod * comb[n - j + l][a[i] - j + l]) % mod;
    cout << f[k][n] << endl;
    return 0;
}

原文地址:https://www.cnblogs.com/suwakow/p/12364818.html

时间: 2024-07-30 21:44:42

[Dwango Programming Contest 6th C] Cookie Distribution的相关文章

Dwango Programming Contest 6th C

Cookie Distribution 题意概述 : 有 \(N\) 个孩子,用 \(K\) 天给孩子们发糖果 第 \(i\) 天有 \(a_i\) 个糖果,等概率地发给这 \(n\) 个孩子(每一天每个孩子最多可以获得一个糖果),设 \(K\) 天后第 \(i\) 个孩子获得的糖果为 \(c_i\) 求 \(\prod_{i = 1}^n c_i\) 的期望乘上 \(\prod_{i = 1}^n \binom N {a_i}\) ,答案对 \(10^9 + 7\) 取模.. \(N \le

Dwango Programming Contest 6th Task C. Cookie Distribution

The answer is number of N-tuples (d[1], d[2], ..., d[N]) in all outcomes, where d[i] means on which day the i-th child get a cookie. Now consider in how many outcomes is there a particular N-tuple (d[1], d[2], ..., d[N]) as described. The answer turn

Dwango Programming Contest 6th -B

期望 按每个空隙计算 对于第$i$个空隙 对于第$j$个跨过这段的概率是$\frac{1}{i-j+1}$ 因为跨过当且仅当$[j+1,i]$之间都不先于$j$合并 求一个逆元前缀和即可 #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5, P = 1e9 + 7; int n; int x[maxn], inv[maxn]; int main() { ios::sync_with_stdio(false

Dwango Programming Contest V 翻车记

A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define N 110 char getc(){char c=getchar();while ((c<'A'||c&

【AtCoder】Dwango Programming Contest V题解

A - Thumbnail 根据题意写代码 #include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define pdi pair<db,int> #define mp make_pair #define pb push_back #define enter putchar('\n') #define space putchar(' ') #define

ZOJ 3703 Happy Programming Contest(0-1背包)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3703 Happy Programming Contest Time Limit: 2 Seconds      Memory Limit: 65536 KB In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two s

Happy Programming Contest zoj3703 dp

Description In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two students loving each other. In the contest, the team will get a lovely balloon with unique color for each problem they solved. Sinc

ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018

ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018 Problem A. Can Shahhoud Solve it? Problem B. Defeat the Monsters Problem C. UCL Game Night Problem

The 2018 ACM-ICPC China JiangSu Provincial Programming Contest快速幂取模及求逆元

题目来源 The 2018 ACM-ICPC China JiangSu Provincial Programming Contest 35.4% 1000ms 65536K Persona5 Persona5 is a famous video game. In the game, you are going to build relationship with your friends. You have N friends and each friends have his upper b