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.问对整个图有几种连接方法,对一个数取模. 解析 要 ...
随机推荐
- SQL Server 查找空值
需要查找某一列为空的数据 )NULL不能用 “=”运算符 )NULL不支持+-*/ <> )不同的函数对NULL的支持不一样,使用前要测试,不能靠猜,不能凭经验
- 利用 Memory Dump Diagnostic for Java (MDD4J) 分析内存管理问题
利用 Memory Dump Diagnostic for Java (MDD4J) 分析内存管理问题(2) 启动和理解 MDD4J[size=1.0625]为了充分理解如何使用 MDD4J,您需要了 ...
- leetcode 293.Flip Game(lintcode 914) 、294.Flip Game II(lintcode 913)
914. Flip Game https://www.cnblogs.com/grandyang/p/5224896.html 从前到后遍历,遇到连续两个'+',就将两个加号变成'-'组成新的字符串加 ...
- sqllite connectionstring setting
https://www.connectionstrings.com/sqlite/ SQLite.NET Basic Data Source=c:\mydb.db;Version=3; Version ...
- 123457123457#0#----com.ppGame.YinYu45--前拼后广--儿童yinyu-pp
com.ppGame.YinYu45--前拼后广--儿童yinyu-pp
- python对 windows系统监控插件
在python编程的windows系统监控中,需要监控监控硬件信息需要两个模块:WMI 和 pypiwin32 .
- Codeforces Round #556 (Div. 2) D. Three Religions 题解 动态规划
题目链接:http://codeforces.com/contest/1150/problem/D 题目大意: 你有一个参考串 s 和三个装载字符串的容器 vec[0..2] ,然后还有 q 次操作, ...
- 什么时候该用readfile() , fread(), file_get_contents(), fgets()?
fread() 和 readfile() fread() 最大一次性能读取 8k长度的字节数,所以不能一次性读取大文件去作下载. 优势在于,操作更加灵活,每次读取指定字节的内容,用于下载时方便控制服务 ...
- 了解 Selenium 定位方式
※元素定位的重要性:在于查找元素 And 执行元素 定位元素的三种方法 1.定位单个元素:在定位单个元素时,selenium-webdriver 提示了如下一些方法对元素进行定位.在这些定位方式中,优 ...
- DeviceEventEmitter React-Native 发送和接受消息(事件监听器)
A页面注册通知: import {DeviceEventEmitter} from 'react-native'; //… //调用事件通知 DeviceEventEmitter.emit('xxxN ...