CF869C The Intriguing Obsession(组合数学瞎搞,O(n)莫名过)
— 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 aa , bb and ccdistinct 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 11 . 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 33 , 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 998244353998244353. 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 aa , bb and cc ( 1<=a,b,c<=50001<=a,b,c<=5000 ) — 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 998244353998244353 .
输入输出样例
说明
In the first example, there are 33 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 2^{3}=823=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
2:每一座桥的距离假设都为1
问:一共有多少种不同的建桥方法,桥的数量可以是任意的合法的数量。
--translate by 万古神犇517
题解:
哇,这场的背景是物语系列啊~又找到了一场动漫场……
首先来考虑一下哪些情况是会被hack掉的
第一种情况显然是同一个区域里连一条边,这样同一个区域里

所以我们一定每次不能连相同区中的两个点,除此之外还有吗?

显然如果一个点连了另一个区域内的两个点,会让这两个点之间的距离变成2,然后GG
于是我们得出了一个结论
如果在两个区域里连点,两个区域内选的点数一定要相等
即a中选出i个点,必须与b中选出i个点相连
连接种类数为

然后我们再来看,如果ab中有两点相连,其中一点再与c相连会出事吗?

很显然不会对答案产生任何影响
所以我们可以得出另外一个结论
a-b b-c c-a所连的边无论如何都是两两独立的
也就是说,如果a-b连边的可能数为x,b-c连边的可能数为y,c-a连边的可能数为z

那么既连ab有连bc的可能性是可以直接用乘法原理推得为xy
同理 ab ca为xz,bc ca为yz
所以总答案就是1+x+y+z+xy+yz+xz+xyz
代码如下:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mod 998244353
using namespace std; long long ans=1ll,fac[],inv[],aa,bb,cc,ab,bc,ca; long long kasumi(long long a,long long b)
{
long long ans=;
while(b)
{
if(b&)
{
ans=((ans%mod)*a)%mod;
}
a=((a%mod)*a)%mod;
b>>=;
}
return ans;
} long long c(long long n,long long m)
{
if(n==m)
{
return ;
}
return (((fac[m]*inv[n])%mod)*inv[m-n])%mod;
} int main()
{
fac[]=;
for(int i=;i<=;i++)
{
fac[i]=fac[i-]*i%mod;
}
inv[]=kasumi(fac[],mod-);
for(int i=;i>=;i--)
{
inv[i]=inv[i+]*(i+)%mod;
}
scanf("%lld%lld%lld",&aa,&bb,&cc);
for(int i=;i<=min(aa,bb);i++)
{
ab+=(((c(i,aa)*c(i,bb))%mod)*fac[i])%mod;
}
for(int i=;i<=min(cc,bb);i++)
{
bc+=(((c(i,cc)*c(i,bb))%mod)*fac[i])%mod;
}
for(int i=;i<=min(aa,cc);i++)
{
ca+=(((c(i,aa)*c(i,cc))%mod)*fac[i])%mod;
}
ca%=mod;
bc%=mod;
ab%=mod;
ans+=ca+bc+ab;
ans+=ca*bc;
ans%=mod;
ans+=ca*ab;
ans%=mod;
ans+=ab*bc;
ans%=mod;
ans+=(((ca*bc)%mod)*ab)%mod;
printf("%lld\n",ans%mod);
}
CF869C The Intriguing Obsession(组合数学瞎搞,O(n)莫名过)的更多相关文章
- CF869C The Intriguing Obsession
思路: 分别在两种不同颜色的岛屿群之间进行搭桥.因为相同颜色的岛屿之间不能有边,任意两个相同颜色的岛屿不能同时和另外一个不同颜色的岛屿都有边.实现: #include <bits/stdc++. ...
- codeforces 869C The Intriguing Obsession【组合数学+dp+第二类斯特林公式】
C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...
- URAL 1203. Scientific Conference(瞎搞)
题目链接 本来觉得这不是经典的贪心吗..果断水一次,wa了,看了看discuss,发现貌似不好水,土土的DP了一下,复杂度很高了,又T了...然后想想单调队列,二分什么的...不好往上加,直接搞了标记 ...
- Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...
- code forces 439 C. The Intriguing Obsession
C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...
- B. Salty Fish Go! -期望题(瞎搞题)
链接:https://www.nowcoder.com/acm/contest/104/B来源:牛客网 题意:A few days ago, WRD was playing a small game ...
- HDU5532 Almost Sorted Array(最长上升子序列 or 瞎搞个做差的数组)
题目链接:点我 题意:给定一个序列,询问是否能删除一个数让它成为非递减或者非递增的序列. 比如说 删除后的序列是1 3 3 5 或者5 3 3 1 或者1 3 5 或者5 3 1 都可以.只要满足删掉 ...
- TOJ3097: 单词后缀 (字典树 or map瞎搞)
传送门 (<---可以点击的~) 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 描述 有些英语单词后缀都是一样的,现在我们需要从给定的一堆单词里 ...
- 8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞
B. Cards 题目连接: http://www.codeforces.com/contest/626/problem/B Description Catherine has a deck of n ...
随机推荐
- 在spring中该如何使用DTO,以及DTO和Entity的关系
1. DTO是用于将后台的数据结构(javaBean)转换为对用户友好的表现方式的数据结构,同时也能防止后台数据直接传送到前台而存在的潜在危险. 2. 可以时候要哪个springbot框架提供的转换器 ...
- openstack网络架构(nova-network/neutron)
openstack网络体系中,网络技术没有创新,但用到的技术点非常庞杂,包括bridge.vlan.gre.vxlan.ovs.openflow.sdn.iptables等,当然这里不会做具体技术介绍 ...
- ubuntu 固定静态IP
http://jingyan.baidu.com/article/e5c39bf5bbe0e739d7603396.html 路由器每重启一次,IP都会改变,那么实验室的路由器一天要断电好几次,那么每 ...
- 将自己数据转化为cifar10支持的lmdb
大家都知道,在caffe里面,要运行cifar10的例子就得先由cifar10的数据库.由于caffe为了提高运行效率,减少磁盘寻道时间等,统一了数据接口(lmdb,leveldb). 首先,看一下c ...
- 恒大威武!关于SQL的一些基础知识整理回顾
首先的首先,恒大威武! 开始正题. 关系代数: 目前主流的关系型数据库,是建立在关系代数的基础上的,即他的数学支撑是关系代数. 关系代数主要包括如下几个二目运算:并运算union.交运算interse ...
- 【Oracle】Oracle 10g利用闪回挽救误删的数据
我们在开发和运维过程中,经常遇到数据被误删除的情况.无论是在应用开发中的Bug,还是修改数据的时候,如果提交了错误数据修改结果,会带来很多问题.一般来说,一旦提交commit事务,我们是不能获取到之前 ...
- Android中RelativeLayout各个属性
android:layout_above="@id/xxx" --将控件置于给定ID控件之上 android:layout_below="@id/xxx" ...
- ARP数据包伪造
一台网络中的计算机,其传递到网络中的数据包的内容是完全由其软硬件逻辑决定的,软件可以操控硬件,硬件亦是一种特殊的软件,所以,接收者只根据数据包的内容,绝不可能判定此数据包的真正来源,一切都是可以伪 ...
- shiro和Spring整合使用注解时没有执行realm的doGetAuthorizationInfo回调方法的解决(XML配置)
在使用Shiro框架进行项目整合时,使用注解在使用Shiro框架进行项目整合时,使用注解在使用Shiro框架进行项目整合时,使用注解@RequiresPermissions为方法提供是需要的权限,但是 ...
- redis 开发与运维 学习心得1
主要是命令相关 第一章 初识Redis 1.redis是基于键值对的NoSQL. 2.redis的值可以是 string, hash, list, set, zset, bitmaps, hyperl ...