C - The Intriguing Obsession Codeforces Round #439 (Div. 2) 找规律-组合数

很傻×,,当时以为这是一个三维的 DP ,,然后稍微推了下 每推出递推方程,,完全没往找规律方面想

后来看CF的 Tutorial 感觉豁然开朗,,给定的同种颜色之间两个island 最小距离为三,,也就是最小的时候是三个不同颜色的点相互连通的时候

也就是说我们只需要找到两两颜色之间的组合方式,,然后这三个相乘就是了

也就是题目中 test 1: 2 ^ 3 = 8 的由来----(因为任意两种)颜色之间的组合方式有两种——连或者不连


然后可以发现两种颜色(个数分别为a b 且 a < b )之间的组合方式为:

 C(a, 0) * C(b, 0) * 0! + C(a, 1) * C(b, 1) * 1! + C(a, 2) * C(b, 2) * 2! + …… C(a, a) * C(b, a) * a!   =  ans1 ;

剩下的就简单了 


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <ctype.h>
#include <vector>
#include <algorithm>
#include <sstream>
#define PI acos(-1.0)
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
using namespace std;
typedef long long ll;
const int maxn = 5000 + 7, INF = 0x7f7f7f7f;
const ll mod = 998244353;
ll a, b, c;
ll C[maxn][maxn];
ll A[maxn];

void init() {
    scanf("%I64d %I64d %I64d", &a, &b, &c);
    if(a > b) swap(a, b); if(b > c) swap(b, c); if(a > b) swap(a, b);
    memset(C, 0, sizeof C);
    C[0][0] = 1;
    for(int i = 1; i < maxn; ++i) {
        C[i][0] = 1;
        for(int j = 1; j <= i; ++j) {
            C[i][j] = (C[i-1][j] + C[i-1][j-1]) % mod;
        }
    }
    A[0] = 1;
    for(int i = 1; i < maxn; ++i) {
        A[i] = (A[i-1] * (ll)i) % mod;
    }
}

ll get(ll a, ll b) {
    ll t = 1LL;
    for(int i = 1; i <= a; ++i) {
        t = (t + ((C[a][i]*C[b][i]%mod)*A[i]%mod)) % mod;
    }
    return t;
}

void solve() {
    ll ans = 1;
    ans = (ans * get(a, b)) % mod; //cout << ans << endl;
    ans = (ans * get(a, c)) % mod; //cout << ans << endl;
    ans = (ans * get(b, c)) % mod;
    cout << ans << endl;
}

int main() {
    init();
    solve();
    return 0;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值