cf 869c The Intriguing Obsession
题意:有三种三色的岛,用a,b,c来标识这三种岛。然后规定,同种颜色的岛不能相连,而且同种颜色的岛不能和同一个其他颜色的岛相连。问有多少种建桥的方法。
题解:em....dp。我们先看两个岛之间怎么个连法。由题意可得岛与岛之间的链接是单射,我们定义f[a][b],表示有a个颜色1的岛和b个颜色2的岛想连的方案数。
首先当a==1 || b==1的时候 f[a][b]=(b+1)或者 (a+1)。然后尝试去找状态转移方程,我们对一个岛去连接另一个岛只有连或者不连两种状态,那么对于不连的状态为f[a-1][b];连的状态为b*f[a-1][b-1],这里要乘上一个b,因为有b个岛可连。
ac代码:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define mt(a) memset(a,0,sizeof(a))
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
typedef long long ll;
ll mod=;
ll f[][];
int main()
{
ll a,b,c;
cin>>a>>b>>c;
int mx=max(a,max(b,c));
mt(f);
for(int i=;i<=mx;i++)
{
f[i][]=i+;
f[][i]=i+;
}
for(int i=;i<=mx;i++)
{
for(int j=;j<=mx;j++)
{
f[i][j]=(j*f[i-][j-]+f[i-][j])%mod;
}
}
ll ans=;
ans=(ans*f[a][b])%mod;
ans=(ans*f[a][c])%mod;
ans=(ans*f[b][c])%mod;
cout<<ans<<endl;
return ;
}
cf 869c The Intriguing Obsession的更多相关文章
- codeforces 869C The Intriguing Obsession【组合数学+dp+第二类斯特林公式】
C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces 869C The Intriguing Obsession
题意:有三种颜色的岛屿各a,b,c座,你可以在上面建桥.联通的点必须满足以下条件:1.颜色不同.2.颜色相同且联通的两个点之间的最短路径为3 其实之用考虑两种颜色的即可,状态转移方程也不难推出:F[i ...
- Codeforces 869C The Intriguing Obsession:组合数 or dp
题目链接:http://codeforces.com/problemset/problem/869/C 题意: 红色.蓝色.紫色的小岛分别有a,b,c个. 你可以在两个不同的岛之间架桥,桥的长度为1. ...
- CodeForces - 869C The Intriguing Obsession(组合数)
题意:有三个集合,分别含有a.b.c个点,要求给这些点连线,也可以全都不连,每两点距离为1,在同一集合的两点最短距离至少为3的条件下,问有多少种连接方案. 分析: 1.先研究两个集合,若每两个集合都保 ...
- 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 ...
- The Intriguing Obsession
C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession
C. The Intriguing Obsession 题目链接http://codeforces.com/contest/869/problem/C 解题心得: 1.由于题目中限制了两个相同 ...
- 【CF Round 439 C. The Intriguing Obsession】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 「日常训练」The Intriguing Obsession(CodeForces Round #439 Div.2 C)
2018年11月30日更新,补充了一些思考. 题意(CodeForces 869C) 三堆点,每堆一种颜色:连接的要求是同色不能相邻或距离必须至少3.问对整个图有几种连接方法,对一个数取模. 解析 要 ...
随机推荐
- MiniDLNA常用操作
# MiniDLNA常用操作 ## 简介 多媒体共享服务器,类似于FTP,支持DLNA的客户端都可以看视频,听音乐,处于同一局域网就可以了 ## 管理 - 启动`systemctl start min ...
- centos下安装ffmpeg加上fdk-aac的支持
本文参考自:https://blog.csdn.net/jklinux/article/details/72367829 安装包可以从这里下载https://download.csdn.net/dow ...
- Dart介绍和环境搭建
/* Dart介绍: Dart是由谷歌开发的计算机编程语言,它可以被用于web.服务器.移动应用 和物联网等领域的开发. Dart诞生于2011年,号称要取代JavaScript.但是过去的几年中一直 ...
- 【Dart学习】--Dart之数组(List)的相关方法总结
一,初始化List 非固定长度list var testList = List(); print(testList.length);//输出0 固定长度List var testList2 = Lis ...
- docker安装并运行mysql
docker拉取mysql镜像: [mall@VM_0_7_centos ~]$ sudo docker pull mysql:5.7 5.7: Pulling from library/mysql ...
- Linux记录-批量安装ssh(转载)
首先,需要检查expect是否安装:rpm -qa|grep expect 然后,在操作机上创建公钥:ssh-keygen 一路回车即可 创建好之后到/root/.ssh/下就可以看到id开头的2个文 ...
- CentOS7下搭建Redis主从复制
(1).实验环境 youxi1 192.168.1.6 Master服务器 youxi2 192.168.1.7 Slave服务器 (2).实验 1)两台服务器上yum安装Redis,启动并设置开机自 ...
- 报错:java.lang.ClassNotFoundException: org.codehaus.jackson.map.JsonMappingException
报错背景: 执行hdfs-mysql的job任务的时候报错. 报错现象: Exception has occurred during processing command Exception: org ...
- How to Plan and Configure YARN and MapReduce 2 in HDP 2.0
As part of HDP 2.0 Beta, YARN takes the resource management capabilities that were in MapReduce and ...
- 【Leetcode_easy】859. Buddy Strings
problem 859. Buddy Strings solution: class Solution { public: bool buddyStrings(string A, string B) ...