嘘~ 正在从服务器偷取页面 . . .

CF_


CF553A Kyoya and Colored Balls 题解

题目链接:CF553A Kyoya and Colored Balls

题意

一个袋子中有 nn 个彩球,他们用 k 种不同的颜色染色。颜色被从 1k 编号。同一种颜色的球看成是一样的。现在从袋中一个一个的拿出球来,直到拿完所有的球。对于所有颜色为 i(1ik1) 的球,他的最后一个球总是在编号比他大的球拿完之前拿完,问这样情况有多少种,答案对 109+7 取模。

输入单组测试数据。 第一行给出一个整数 k(1k1000),表示球的种类。 接下来 k 行,每行一个整数 ci,表示第 i 种颜色的球有 ci(1ci1000)。 球的总数目不超过 1000

发烧真的无聊所以就写写题目啥的吧23333

考虑依次插入每种颜色的球,不妨设现在要插入的球颜色为 i ,有 xi

ni 为之前已经插入的球的数量,即

ni=i1j=1xi

对于 i 的最后一个球,一定是要放在序列的最后面的

剩下的 xi1 个球可以随便在 ni1 个空隙里面放,每个空隙可以放多个球

或者也可以认为,把剩下的 xi1 个球分成 ni1 个组,每个组可以为空

显然根据插板法可知共有 (ni+xi1ni) 种方案

因此总的答案就是

ki=1(ni+xi1ni)

时间复杂度 O(n2)

代码:

cpp
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <random>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define N (int)(1e3+15)

const int p=1e9+7;
int n,k,res=1,C[N][N];
void mul(int &x,int y){x=x*(y%p)%p;}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    // freopen("check.in","r",stdin);
    // freopen("check.out","w",stdout);
    for(int i=0; i<=1000; i++)
    {
        C[i][0]=1;
        for(int j=1; j<=i; j++)
            C[i][j]=(C[i-1][j]+C[i-1][j-1])%p;
    }
    cin >> k;
    for(int i=1,x; i<=k; i++)
    {
        cin >> x;
        mul(res,C[n+x-1][n]);
        n+=x;
    }
    cout << res << '\n';
    return 0;
}

不行了要命了。


文章作者: q779
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-ND 4.0 许可协议。转载请注明来源 q779 !
评论
你认为这篇文章怎么样?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v3.1.3
  目录