Codeforces Round #439 (Div. 2)-The Intriguing Obsession(DP)
来源:互联网 发布:矩阵怎么计算 编辑:程序博客网 时间:2024/05/29 02:12
— 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 a, b 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.
The first and only line of input contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 5 000) — the number of islands in the red, blue and purple clusters, respectively.
Output one line containing an integer — the number of different ways to build bridges, modulo 998 244 353.
1 1 1
8
1 2 2
63
1 3 5
3264
6 2 9
813023575
In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is23 = 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,问你有多少种连接方式。
题解:三种颜色时必须是间隔开来,其实可以看做一次挑两种颜色里的岛屿相连,好吧,其实就是组成二分图。
然而比赛的时候没想到,最后将三种二分图的种数相乘就是答案了。
#include<set> #include<map> #include<stack> #include<queue> #include<vector> #include<string> #include<time.h> #include<math.h> #include<stdio.h> #include<iostream> #include<string.h> #include<stdlib.h> #include<algorithm> #include<functional> using namespace std; #define ll __int64 #define lowbit(x) (x&-x) #define inf 2147483647 #define mod 998244353 #define maxn 5005 #define eps 1e-9 ll dp[maxn][maxn];int main(void){int i,j,a,b,c;for(i=0;i<=5000;i++)dp[0][i]=1;for(i=1;i<=5000;i++){dp[i][0]=1;for(j=1;j<=5000;j++)dp[i][j]=(dp[i-1][j]+dp[i-1][j-1]*j)%mod;}scanf("%d%d%d",&a,&b,&c);ll ans=dp[a][b]*dp[a][c]%mod*dp[b][c]%mod;printf("%I64d\n",(ans+mod)%mod);return 0;}
- Codeforces Round #439 (Div. 2)-The Intriguing Obsession(DP)
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession dp
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession(dp)
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession 数学
- Codeforces Round #439 (Div. 2) 869 C. The Intriguing Obsession
- CF round#439 div.2 C The Intriguing Obsession【DP】
- Codeforces Round #439 (Div. 2)C. The Intriguing Obsession (组合数详解)
- Codeforces Round #439 C The Intriguing Obsession(dp)
- Codeforces Round #439 C.The Intriguing Obsession(DP + 思维)
- Codeforces 869C ( Codeforces Round #439 (Div. 2) ) The Intriguing Obsession 组合数学
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession(组合数)
- Codeforces Round #439 (Div. 2) C The Intriguing Obsession (组合数学)
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession 组合数学
- Codeforces Round #439 (Div. 2) C 869C The Intriguing Obsession(思维+简单组合)
- Codeforces Round #439 (Div. 2) C.The Intriguing Obsession(组合数、记忆化搜索)
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity (hash+数状数组)
- JAVA课堂练习
- FTPrep, 108 Convert Sorted Array to Binary Search Tree
- EU5-12:Talking about the future technology
- 学习JavaScript数据结构与算法(四)——链表
- Codeforces Round #439 (Div. 2)-The Intriguing Obsession(DP)
- JAVA提高篇(18)--BufferedReader、BufferedWriter
- FTPrep, 109 Convert Sorted List to Binary Search Tree
- Ubuntu16.04 安装百度云bcloud
- python邮件SMTP的GUI编程
- bootstrap的简单实用
- sudo给某些用户添加以root权限运行某些命令
- PTA 2.3
- [数位DP] ZROI 2017 提高3 T1 树状数组