codeforces869c The Intriguing Obsession

本文探讨了一个有趣的问题:在三个不同颜色的岛屿群中,如何计算符合特定条件的桥梁搭建方式的数量。通过动态规划的方法,文章提供了一种有效的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C. The Intriguing Obsession
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

— This is not playing but duty as allies of justice, Nii-chan!

— Not allies but justice itself, Onii-chan!

With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands!

There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of ab and c distinct islands respectively.

Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.

The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998 244 353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other.

Input

The first and only line of input contains three space-separated integers ab and c (1 ≤ a, b, c ≤ 5 000) — the number of islands in the red, blue and purple clusters, respectively.

Output

Output one line containing an integer — the number of different ways to build bridges, modulo 998 244 353.

Examples
input
Copy
1 1 1
output
8
input
Copy
1 2 2
output
63
input
Copy
1 3 5
output
3264
input
Copy
6 2 9
output
813023575
Note

In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 23 = 8.

In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively.

题意:给你三个集合,每个集合内有点,规定统一集合内两点最短路要么为3要么不连通,求方案数。
题解:
我们定义dp[i][j]表示集合1加了i个点,集合2加了j个点时的方案数。
显然 dp[i][j]=(dp[i-1][j]+(dp[i-1][j-1]*j));
情况
#include <stdio.h>
long long dp[5001][5001],a,b,c;
int main()
{
    scanf("%I64d%I64d%I64d",&a,&b,&c);
    for(int i=0;i<=5000;i++) dp[i][0]=dp[0][i]=1;
    for(int i=1;i<=5000;i++)
        for(int j=1;j<=5000;j++)
            dp[i][j]=(dp[i-1][j]+(dp[i-1][j-1]*j)%998244353)%998244353;
    printf("%I64d\n",(dp[a][b]*dp[a][c])%998244353*dp[b][c]%998244353);
}

一种是加边,随意一个其他点,或者不加。
n^2可以通过本题数据。
之后直接算答案就行了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值