Avito Cool Challenge 2018 C. Colorful Bricks 【排列组合】
传送门:http://codeforces.com/contest/1081/problem/C
2 seconds
256 megabytes
standard input
standard output
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are nn bricks lined in a row on the ground. Chouti has got mm paint buckets of different colors at hand, so he painted each brick in one of those mm colors.
Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are kk bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure).
So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998244353998244353.
The first and only line contains three integers nn, mm and kk (1≤n,m≤2000,0≤k≤n−11≤n,m≤2000,0≤k≤n−1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it.
Print one integer — the number of ways to color bricks modulo 998244353998244353.
3 3 0
3
3 2 1
4
In the first example, since k=0k=0, the color of every brick should be the same, so there will be exactly m=3m=3 ways to color the bricks.
In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 44 possible colorings.

题意概括:
N 个 方块, M 种颜色,存在 K 个方块使得它与相邻左边的方块颜色不同。
求涂色方案数。
解题思路:
换角度思考,其实就是 求把 N块方块分成 K+1块与相邻左边涂色不同的方案数。
杨辉三角求组合数 C(N-1, K), 因为第一块不考虑与左边颜色的关系 有 M 种可能,其余的都要去掉左边那一块的颜色,所以只有 M-1种可能,即 M*(M-1)*(M-1)*......*(M-1) ;
分块方案数 * 颜色方案数 即最后答案。
AC code:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
const int MAXN = 2e3+;
const LL MOD = ;
LL c[MAXN][MAXN]; LL qpow(LL x, LL n)
{
LL res = 1LL;
while(n){
if(n&) res = ((res%MOD*x%MOD)+MOD)%MOD;
x = x*x%MOD;
n>>=1LL;
}
return res;
} int main()
{
LL N, M, K;
cin >> N >> M >> K;
//memset(c, 1LL, sizeof(1LL));
c[][] = c[][] = c[][] = 1LL; for(int i = ; i <= N; i++){
c[i][] = 1LL;
for(int j = ; j < i; j++){
c[i][j] = (c[i-][j-] + c[i-][j])%MOD;
}
c[i][i] = 1LL;
} //cout << c[N-1][K]; LL ans = 1LL;
ans = (M%MOD*c[N-][K]%MOD*qpow(M-1LL, K)%MOD + MOD)%MOD;
cout << ans << endl;
return ; }
Avito Cool Challenge 2018 C. Colorful Bricks 【排列组合】的更多相关文章
- Avito Cool Challenge 2018 C - Colorful Bricks
题目大意: 1*n的格子 可以用m种颜色涂色 已知从第2开始到第n个格子 有k个格子与其左边的格子颜色不同 求涂色的方案数 相当于把n个格子分成k+1份 可以递推出分成k+1份的不同的方案数(其实递推 ...
- Codeforces Avito Code Challenge 2018 D. Bookshelves
Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/ ...
- Avito Cool Challenge 2018:C. Colorful Bricks
C. Colorful Bricks 题目链接:https://codeforces.com/contest/1081/problem/C 题意: 有n个横向方块,一共有m种颜色,然后有k个方块的颜色 ...
- Avito Cool Challenge 2018
考挂了.. A - Definite Game 直接看代码吧. #include<cstdio> #include<cstring> #include<algorithm ...
- Avito Cool Challenge 2018(div1+2)
A. Definite Game: 题意:输入N,输出最小的结果N-x,其中x不少N的因子. 思路:N=2时,输出2:其他情况输出1:因为N>2时,N-1不会是N的因子. #include< ...
- Avito Cool Challenge 2018 Solution
A. Definite Game 签. #include <bits/stdc++.h> using namespace std; int main() { int a; while (s ...
- Avito Code Challenge 2018
第一次打CF,很菜,A了三道水题,第四题好像是是数位DP,直接放弃了.rateing从初始的1500变成了1499,还是绿名,这就很尴尬.之后觉得后面的题目也没有想象的那么难(看通过人数)过两天吧剩下 ...
- Avito Cool Challenge 2018 自闭记
A:n==2?2:1. #include<iostream> #include<cstdio> #include<cmath> #include<cstdli ...
- Avito Cool Challenge 2018 E. Missing Numbers 【枚举】
传送门:http://codeforces.com/contest/1081/problem/E E. Missing Numbers time limit per test 2 seconds me ...
随机推荐
- css样式margin padding border
- java线程总结1--线程的一些概念基础以及线程状态
在编程中,很多时候,我们需要计算机同时处理多件事情,例如说,就拿我相对最熟悉的web服务来说,web程序必须支持多用户访问,要不然如果你的用户只能支持一个用户在线访问,其他用户只能以排队的形式等待,估 ...
- JavaScript(JS)计算某年某月的天数(月末)
方法1 /** * 获取某年月的天数 * @param year 年 * @param month 月(0-11) * @returns {number} 天数 */ var getDaysOfMon ...
- 二、redis的配置
# redis 配置文件示例 # 当你需要为某个配置项指定内存大小的时候,必须要带上单位, # 通常的格式就是 1k 5gb 4m 等酱紫: # # 1k => 1000 bytes # 1kb ...
- [TJOI2007]小朋友
题面 Luogu Sol 弦图最大独立集 做法见上篇博客 # include <bits/stdc++.h> # define RG register # define IL inline ...
- (1-3)line-height与图片的表现
(1-3)line-height与图片的表现 这篇文章真的很重要,耐心看,重中之重. 一.行高和图片的表现 图片和行高有什么歪腻呢?? 很多人不明白,为什么我图片好好的放在一个标签里面它就出现了如下问 ...
- Java xml 操作(Dom4J修改xml + xPath技术 + SAX解析 + XML约束)
1 XML基础 1)XML的作用 1.1 作为软件配置文件 1.2 作为小型的"数据库" 2)XML语法(由w3c组织规定的) 标签: 标签名不能以数字开头,中间不能有空格,区分大 ...
- awk获取外部变量
语法 awk [ -F re] [parameter...] ['pattern {action}' ] [-f progfile][in_file...] 获得普通外部变量 [xingxing.dx ...
- 关联函数 map 的基本用法
1.map简介 map是一类关联式容器.它的特点是增加和删除节点对迭代器的影响很小,除了那个操作节点,对其他的节点都没有什么影响.对于迭代器来说,可以修改实值,而不能修改key. 2.map的功能 自 ...
- UTF-8文件编码格式中有无签名问题汇总(BOM)
UTF-8签名(UTF-8 signature)也叫做BOM(Byte order Mark),是UTF编码方案里用于标识编码的标准标记.如果多个文件设置了签名,在二进制流中就会包含多个UTF-8签名 ...