美文网首页
The Intriguing Obsession CodeFor

The Intriguing Obsession CodeFor

作者: laochonger | 来源:发表于2018-03-20 10:33 被阅读0次

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

Input
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
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 2^3= 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.

题意:有三座不同颜色的岛屿,同种颜色的岛屿间不能直接连接或者不能仅通过一种颜色的岛屿为媒介进行连接(同种颜色的岛屿不能连在同一点),任意两个岛屿既可以连接也可以不连接,问总共有多少种连接方式,最终的答案需要mod。

题解:直接拆分为三个二分图,通过排列组合可以得出答案,但是直接排列组合会发现不知道在哪里取余,而且复杂度高,正解应该是递推:
我们可以将a,b,c三个数分成(a,b,1),(a,c,1),(b,c,1)

将上述的三种情况相乘再取模就是最终的答案

而对于任意一种情况a,b

F(a,b)=f(a-1,b-1)*b+f(a-1,b)
(我...tm)

#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef unsigned int ui;

llu sum = 1;
void solve(int a, int b){
    if(a > b){
        int temp = a;
        a = b;
        b = temp;
    }
    llu sum_2 = 1;//不连通为初值
    llu s1,s2,s3;
    for(int i = 1; i <= a; i++){
        s1 = 1;s2 = 1;s3 = 1;
        for(int j = 1; j <= i; j++){
            s1*=(a-j+1);
            s2*=j;
        }
        for(int j = 1; j <= i; j++){
            s3*=(b-j+1); 
        }
        sum_2 += (s1/s2*s3);
    }
    sum *= sum_2;
}


int main(){
    int a,b,c;
    while(scanf("%d%d%d" , &a, &b,&c) != EOF){
        sum = 1;
        solve(a,b);
        solve(a,c);
        solve(b,c);
        printf("%I64d\n", sum);
    }
    return 0;
}

这是我一开始写的代码(显然是错的...)

#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;  
}  

这是大神的代码...(显然一看模板就不知道比我高到哪里去了)

相关文章

网友评论

      本文标题:The Intriguing Obsession CodeFor

      本文链接:https://www.haomeiwen.com/subject/dojvqftx.html