C

来源:互联网 发布:入门鼠标推荐 知乎 编辑:程序博客网 时间:2024/06/17 17:41

很傻×,,当时以为这是一个三维的 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;}



原创粉丝点击