• Codeforces 869 C The Intriguing Obsession


    题目描述

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

    输入输出样例

    输入样例#1: 
    1 1 1
    
    输出样例#1: 
    8
    
    输入样例#2: 
    1 2 2
    
    输出样例#2: 
    63
    
    输入样例#3: 
    1 3 5
    
    输出样例#3: 
    3264
    
    输入样例#4: 
    6 2 9
    
    输出样例#4: 
    813023575
    

    说明

    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.

    因为同色岛之间的最短路径长度>=3,所以同色岛之间不能有边并且一个岛不能连两个同色岛。

    于是我们可以分别求一下2色到1色的方案数,3色到1色的方案数,3色到2色的方案数,然后把它们乘起来就好啦。

    求一个搭配的方案数要用一下组合数。。。。

    #include<bits/stdc++.h>
    #define ll long long
    #define maxn 5005
    const int ha=998244353;
    using namespace std;
    int jc[maxn],ni[maxn];
    int ans=0,a,b,c;
    
    inline int ksm(int x,int y){
    	int an=1;
    	for(;y;y>>=1,x=x*(ll)x%ha) if(y&1) an=an*(ll)x%ha;
    	return an;
    }
    
    inline int add(int x,int y){
    	x+=y;
    	return x>=ha?x-ha:x;
    }
    
    inline void init(){
    	jc[0]=1;
    	for(int i=1;i<=5000;i++) jc[i]=jc[i-1]*(ll)i%ha;
    	ni[5000]=ksm(jc[5000],ha-2);
    	for(int i=5000;i;i--) ni[i-1]=ni[i]*(ll)i%ha;
    }
    
    inline int P(int x,int y){
    	return x<y?0:jc[x]*(ll)ni[x-y]%ha;
    }
    
    inline int C(int x,int y){
    	return x<y?0:P(x,y)*(ll)ni[y]%ha;
    }
    
    int main(){
    	init();
    	cin>>a>>b>>c;
    	for(int i=0;i<=b;i++) ans=add(ans,C(b,i)*(ll)P(a,b-i)%ha);
    	int an[2];
    	an[0]=an[1]=0;
    	for(int i=0;i<=c;i++){
    		an[0]=add(an[0],C(c,i)*(ll)P(a,c-i)%ha);
    		an[1]=add(an[1],C(c,i)*(ll)P(b,c-i)%ha);
    	}
    	
    	ans=ans*(ll)an[0]%ha*(ll)an[1]%ha;
    	
    	printf("%d
    ",ans);
    	return 0;
    }
    

      

  • 相关阅读:
    @Value注解无法为static 变量赋值
    CloseableHttpClient方式配置代理服务器访问外网
    微信小程序上传图片
    centos7 无界面静默安装 oracle
    Linux安装配置JDK
    java导出Excel定义导出模板
    ECharts柱状图
    Java获取客户端真实IP
    Eclipse控制台输出log日志中文乱码
    $_SRRVER常用用法
  • 原文地址:https://www.cnblogs.com/JYYHH/p/8503117.html
Copyright © 2020-2023  润新知