传送门:http://codeforces.com/contest/1081/problem/C

C. Colorful Bricks
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print one integer — the number of ways to color bricks modulo 998244353998244353.

Examples
input

Copy
3 3 0
output

Copy
3
input

Copy
3 2 1
output

Copy
4
Note

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 【排列组合】的更多相关文章

  1. Avito Cool Challenge 2018 C - Colorful Bricks

    题目大意: 1*n的格子 可以用m种颜色涂色 已知从第2开始到第n个格子 有k个格子与其左边的格子颜色不同 求涂色的方案数 相当于把n个格子分成k+1份 可以递推出分成k+1份的不同的方案数(其实递推 ...

  2. Codeforces Avito Code Challenge 2018 D. Bookshelves

    Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/ ...

  3. Avito Cool Challenge 2018:C. Colorful Bricks

    C. Colorful Bricks 题目链接:https://codeforces.com/contest/1081/problem/C 题意: 有n个横向方块,一共有m种颜色,然后有k个方块的颜色 ...

  4. Avito Cool Challenge 2018

    考挂了.. A - Definite Game 直接看代码吧. #include<cstdio> #include<cstring> #include<algorithm ...

  5. Avito Cool Challenge 2018(div1+2)

    A. Definite Game: 题意:输入N,输出最小的结果N-x,其中x不少N的因子. 思路:N=2时,输出2:其他情况输出1:因为N>2时,N-1不会是N的因子. #include< ...

  6. Avito Cool Challenge 2018 Solution

    A. Definite Game 签. #include <bits/stdc++.h> using namespace std; int main() { int a; while (s ...

  7. Avito Code Challenge 2018

    第一次打CF,很菜,A了三道水题,第四题好像是是数位DP,直接放弃了.rateing从初始的1500变成了1499,还是绿名,这就很尴尬.之后觉得后面的题目也没有想象的那么难(看通过人数)过两天吧剩下 ...

  8. Avito Cool Challenge 2018 自闭记

    A:n==2?2:1. #include<iostream> #include<cstdio> #include<cmath> #include<cstdli ...

  9. Avito Cool Challenge 2018 E. Missing Numbers 【枚举】

    传送门:http://codeforces.com/contest/1081/problem/E E. Missing Numbers time limit per test 2 seconds me ...

随机推荐

  1. java中四种引用类型(对象的强、软、弱和虚引用)

    对象的强.软.弱和虚引用在JDK 1.2以前的版本中,若一个对象不被任何变量引用,那么程序就无法再使用这个对象.也就是说,只有对象处于可触及(reachable)状态,程序才能使用它.从JDK 1.2 ...

  2. js 递归树结构数据查找父级

    1.json树数据查找所有父级--完成 json:树结构数据 var arrData = [{ "label": "中国", "City": ...

  3. Linux下剪切拷贝命令

    Linux下剪切拷贝命令   命令格式: mv   source    dest   mv: 命令字   source: 源文件   dest: 目的地址   Linux下拷贝命令   命令格式:cp ...

  4. 建一个springboot项目

    1.打开 https://start.spring.io/ 新建一个maven的demo,这里选择的是1.5.18的版本 2.将自动生成的demo导入eclipse,直接选中File里的import, ...

  5. laravel上传到七牛图片插件

    1.首先引入两个插件 2.在https://developer.qiniu.com/kodo/sdk/1241/php找到安装命令 在终端运行composer require qiniu/php-sd ...

  6. 优秀iOS文章集合

    Runtime 10种用法(没有比这更全的了成为iOS顶尖高手,你必须来这里(这里有最好的开源项目和文章)iOS逆向Reveal查看任意app 的界面JSPatch (实时修复App Store bu ...

  7. 删除SVN版本信息 .svn文件夹

    环境:MyEclipse.Windows 问题描述: 在MyEclipse中当我们需要将一个文件夹(包含若干文件或嵌套文件夹)拷贝到另一个文件夹时,此时文件内容虽然拷贝过去了,但其下面的 .svn文件 ...

  8. Java从入门到精通——数据库篇Mongo DB GridFS文件系统

    一.概述    GridFS是MongoDB的一种存储机制,用来存储大型二进制文件. 优点: 1.使用GridFS能够简化你的栈.如果已经在使用MongoDB,那么可以使用GridFS来代替独立的文件 ...

  9. 微信小程序开发4-JSON

    1.JSON是JavaScript语法的子集 2.JSON的语法规则 数据在名称/值对中 数据由逗号分隔 大括号保存对象 中括号保存数组 3.JSON 值可以是: 数字(整数或浮点数) 字符串(在双引 ...

  10. arcgis server10.1 gp GetResultMapServiceLayer

    根据10.1文档 silverlight 里面提供了新的_geoprocessorTask.GetResultMapServiceLayer方法 研究了一下得知 原来的GetResultImageLa ...