Codeforces Round #439 (Div. 2) C The Intriguing Obsession (组合数学)

本文解析了 Codeforces 平台上的题目 869C 的解题思路,通过理解题目中“至少3”的含义,将问题转换为确保不同颜色岛屿间最短距离不小于3的问题。文章进一步提出将图分为三部分来简化问题,并提供了一个 O(n^2) 的暴力求解方法,同时展示了如何将其优化到 O(n) 的效率。

tutiol: http://codeforces.com/blog/entry/55009

别人的代码;

Problem C

Consider islands of two colours and the bridges between them.
869C - The Intriguing Obsession

First step: Consider what does at least 3 mean?

'The shortest distance between them is at least 3' means it can't be 1 or 2. The distance can't be 1 means that no two islands with the same colour can be straightly connected. The distance can't be 2 means that for each island, no two islands with the same colour can both be straightly connected with it.

Second step: Make the graph into 3 parts.

The bridges between red and blue islands have no effection with those between red and purple ones. Therefore, we can make the graph into 3 parts: one between red and blue, one between blue and purple, and the last one between red and purple.

Suppuse there are A red islands and B blue islands, and there are k bridges between them. Then, the answer will be . So, the answer of bridges between red and blue ones should be

Therefore, the final answer should be ans1 * ans2 * ans3.

You can calculate it with an O(n2) brute force. Also, you can make it into O(n).

#include<cstdio>
#include<iostream>
using namespace std;
#define mod 998244353
#define maxn 5010
int C[maxn][maxn];
long long jie[maxn];
long long solve(int n,int m)
{
    long long ans=0;
    int lim=min(n,m);
    for(int i=0; i<=lim; i++)
        ans=(ans+1ll*C[n][i]*C[m][i]%mod*jie[i]%mod)%mod;
    return ans;
}
int main()
{
    C[0][0]=1;
    for(int i=1; i<=5000; i++)
    {
        C[i][0]=1;
        for(int j=1; j<=i; j++)
        {
            C[i][j]=(C[i-1][j]+C[i-1][j-1]);
            if(C[i][j]>=mod) C[i][j]-=mod;
        }
    }
    jie[0]=1;
    for(int i=1; i<=5000; i++)
        jie[i]=1ll*jie[i-1]*i%mod;
    int a,b,c; scanf("%d%d%d",&a,&b,&c);
    long long ans=solve(a,b)*solve(a,c)%mod;
    ans=ans*solve(b,c)%mod;
    cout<<ans<<endl;
    return 0;
}
基于部落竞争与成员合作算法(CTCM)融合动态窗口法DWA的无人机三维动态避障方法研究,MATLAB代码 动态避障路径规划:基于部落竞争与成员合作算法(CTCM)融合动态窗口法DWA的无人机三维动态避障方法研究,MATLAB 融合DWA的青蒿素优化算法(AOA)求解无人机三维动态避障路径规划,MATLAB代码 基于动态环境下多智能体自主避障路径优化的DWA算法研究,MATLAB代码 融合DWA的青蒿素优化算法AOA求解无人机三维动态避障路径规划,MATLAB代码 基于DWA的多智能体动态避障路径规划算法研究,MATLAB代码 融合动态窗口法DWA的粒子群算法PSO求解无人机三维动态避障路径规划研究,MATLAB代码 基于粒子群算法PSO融合动态窗口法DWA的无人机三维动态避障路径规划研究,MATLAB代码 基于ACOSRAR-DWA无人机三维动态避障路径规划,MATLAB代码 基于ACOSRAR-DWA无人机三维动态避障路径规划,MATLAB代码 基于DWA的动态环境下无人机自主避障路径优化,MATLAB代码 基于DWA的动态环境下机器人自主避障路径规划,MATLAB代码 基于城市场景下RRT、ACO、A*算法的无人机三维路径规划方法研究,MATLAB代码 基于城市场景下无人机三维路径规划的导航变量的多目标粒子群优化算法(NMOPSO),MATLAB代码 导航变量的多目标粒子群优化算法(NMOPSO)求解复杂城市场景下无人机三维路径规划,MATLAB代码 原创:5种最新多目标优化算法求解多无人机协同路径规划(多起点多终点,起始点、无人机数、障碍物可自定义),MATLAB代码 原创:4种最新多目标优化算法求解多无人机协同路径规划(多起点多终点,起始点、无人机数、障碍物可自定义),MATLAB代码 高维超多目标优化:基于导航变量的多目标粒子群优化算法(NMOPSO)的无人机三维
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值