C - The Intriguing Obsession /* Codeforces Round #439 */ (dp )

— 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.

Example

Input

1 1 1

Output

8

Input

1 2 2

Output

63

Input

1 3 5

Output

3264

Input

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.

题意:岛屿有三种颜色,每种颜色有a,b,c座,连桥的话,桥长为1,同种颜色之间不能连桥,或者他们之间的距离不能小于3,问有多少种连法?

参考代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 const int INF=0x3f3f3f3f;
 5 const int SIZE=5010;
 6 const int MOD=998244353;
 7 typedef long long LL;
 8 LL dp[SIZE][SIZE];
 9 int main()
10 {
11     LL a,b,c;
12     scanf("%I64d%I64d%I64d",&a,&b,&c);
13     LL n=max(a,max(b,c));
14
15     for(int i=0;i<=n;i++)
16         dp[i][0]=dp[0][i]=1;
17     ///前面的情况肯定是默认为1 ,方便下面的与前面相乘
18
19     for(int i=1;i<=n;i++)
20         for(int j=1;j<=n;j++)
21             dp[i][j]=(dp[i-1][j-1]*i+dp[i][j-1])%MOD;
22             ///连的话与前面情况相乘+不连
23
24     LL ans=1;
25     ans=dp[a][b]*ans%MOD;
26     ans=dp[a][c]*ans%MOD;
27     ans=dp[b][c]*ans%MOD;
28
29     ///每两种颜色之间的种类
30     printf("%I64d\n",ans);
31     return 0;
32 }

时间: 2024-11-13 10:41:07

C - The Intriguing Obsession /* Codeforces Round #439 */ (dp )的相关文章

Codeforces 869C The Intriguing Obsession:组合数 or dp

题目链接:http://codeforces.com/problemset/problem/869/C 题意: 红色.蓝色.紫色的小岛分别有a,b,c个. 你可以在两个不同的岛之间架桥,桥的长度为1. 任意两个颜色相同的岛之间的距离不能小于3. 问你合法的架桥方案数. 题解: 显然只能在不同颜色的岛之间连边. 而且一个岛对于一种颜色,最多只能连一个岛. 设f(x,y)表示两种颜色的岛相互连边,分别有x,y个,连边的方案数.(x < y) 那么ans = f(a,b) * f(b,c) * f(a

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

DP Codeforces Round #303 (Div. 2) C. Woodcutters

题目传送门 1 /* 2 题意:每棵树给出坐标和高度,可以往左右倒,也可以不倒 3 问最多能砍到多少棵树 4 DP:dp[i][0/1/2] 表示到了第i棵树时,它倒左或右或不动能倒多少棵树 5 分情况讨论,若符合就取最大值更新,线性dp,自己做出来了:) 6 */ 7 #include <cstdio> 8 #include <algorithm> 9 #include <cstring> 10 #include <cmath> 11 #include &

Codeforces Round #267 (Div. 2) C. George and Job(DP)补题

Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the follow

Educational Codeforces Round 26 D. Round Subset(dp)

题目链接:Educational Codeforces Round 26 D. Round Subset 题意: 给你n个数,让你选其中的k个数,使得这k个数的乘积的末尾的0的个数最大. 题解: 显然,末尾乘积0的个数和因子2和因子5的个数有关. 然后考虑dp[i][j]表示选i个数,当前因子5的个数为j时,能得到因子2最多的为多少. 那么对于每个数,记录一下因子2和5的个数,做一些01背包就行了. 1 #include<bits/stdc++.h> 2 #define mst(a,b) me

Educational Codeforces Round 26 D dp,思维

Educational Codeforces Round 26 D. Round Subset 题意:有 n 个数,从中选出 k 个数,要使这 k 个数的乘积末尾的 0 的数量最多. tags:dp好题 dp[i][j][l] 表示前 i 个数,选取了其中 j 个数,分解因子后有 l 个 5时,最多有多少个 2 .i 这一维明显可以省略. 这题一开始有个地方写挫了..选取 j 个数时,应该反着来,即 for( j, k, 1) ,不是 for( j, 1, k) ,不然会多算. #include

Codeforces Round #260 (Div. 1) A. Boredom (DP)

题目链接:http://codeforces.com/problemset/problem/455/A A. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alex doesn't like boredom. That's why whenever he gets bored, he comes up with

Codeforces Round #433 (Div. 1) D. Michael and Charging Stations(dp)

题目链接:Codeforces Round #433 (Div. 1) D. Michael and Charging Stations 题意: 一个人每天要加油,1种为1000,1种为2000,如果付全额,会得到10%的回扣放在卡上. 如果卡上有剩余的回扣,可以拿来抵现金.问n天最少需要花多少钱. 题解: 很直观的一个dp就是考虑dp[i][j],表示第i天卡上剩余回扣为j的最小花费. 将所有的数除以100后,j其实是小于40的,严格的说是小于30,官方题解有个证明. 因为卡上不可能积累很多的