BNUOJ 51280 组队活动(dp + 计数)

题意:

1NN,M,MN1000,

分析:

f[i]:=i()
f[0]=1,f[i]=j=0m1Cji1f[i1j]
1,i1j,Cji1
i1jf[i1j],jCji1f[i1j]
j[0,m1],f[i]
ans=f[n],O(nm)

cdqntt,: 地址

代码:

//
// Created by TaoSama on 2016-02-12
// Copyright (c) 2016 TaoSama. All rights reserved.
//
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e3 + 10, INF = 0x3f3f3f3f, MOD = 998244353;

int n, m;
long long c[N][N], f[N];

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    for(int i = 0; i <= 1000; ++i) {
        c[i][0] = c[i][i] = 1;
        for(int j = 1; j < i; ++j)
            c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;
    }

    int t; scanf("%d", &t);
    while(t--) {
        scanf("%d%d", &n, &m);
        f[0] = 1;
        for(int i = 1; i <= n; ++i) {
            f[i] = 0;
            for(int j = 0; j <= min(i - 1, m - 1); ++j) {
                f[i] += c[i - 1][j] * f[i - 1 - j] % MOD;
                f[i] %= MOD;
            }
        }
        printf("%lld\n", f[n]);
    }
    return 0;
}

你可能感兴趣的:(dp,计数)