ReiAC's Blog

Recent content on ReiAC's Blog

马上订阅 ReiAC's Blog RSS 更新: https://rei.ac/index.xml

ICPC2014西安 F Color

2021年5月27日 18:27

https://codeforces.com/gym/100548/problem/F

题目大意

$N$朵花排成一行,我们有$M$种颜色,可以给这些花涂色,保证相邻的花的颜色不同

求最后恰好使用了$k$种颜色的方案数。

推算

第一反应就是 $\complement_m^k\ast\ k\left(k-1\right)^{n-1}$ 当想了一下之后好像不对,这个公式算出来的是使用小于等于$k$种颜色的方案数量

然后推出如下公式 $\complement_k^x\ast x\left(x-1\right)^{n-1}$ 这个公式的含义是从$k$种颜色中再选出来$x$种使得相邻的格子不同色最后的颜色数小于等于$x$,每一个集合都有交,用容斥原理来处理

设 $S = F[x]=\complement_k^x\ast x\left(x-1\right)^{n-1}$

$ans=\complement_m^k\sum\left(-1\right)^{k-i}\complement_k^i\ast\ i\left(i-1\right)^{n-1}$

记得开long long

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<bits/stdc++.h>
#define int long long//__int128
#define mmst0(x) memset(x,0,sizeof(x))
#define mmst3f(x) memset(x,0x3f,sizeof(x))
#define pb(x) emplace_back(x)
#define mkp(x, y) make_pair(x, y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double rld;
typedef unsigned long long ull;

const rld eps = 1e-6;
const int INF=0x3f3f3f3f;//0x3f3f3f3f3f3f3f3f;//LLINF
const int N=(int)1e6+10,mod=1e9+7;

int read(){int s=0,w=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-'...

剩余内容已隐藏

查看完整文章以阅读更多