传送门: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. pom resource配置

    maven pom配置资源resource, make时可自动发布到release目录的 \WEB-INF\classes 下. 解决使用idea时, 每次都需要配置资源文件的手动配置. 具体: &l ...

  2. Eclipse 常见问题总结

    添加包 1.build path 直接添加 2.在windows-->preferences -> Java -> build path -> classpath variab ...

  3. Java基础(七)常用类

    一.Math类 1.Math类介绍 Math类属于java.lang包下面,里面包含用于执行基本数学运算的方法,如初等指数,对数,平方根和三角函数,该类被final修饰. 常用字段: 1.E 表示自然 ...

  4. 3、springboot之热部署

    我用的是idea 一.开启idea自动make功能 1.CTRL + SHIFT + A --> 查找make project automatically --> 选中 2.CTRL + ...

  5. Effective C++ .07 virtual析构函数的提供

    主要讲了, 1. virtual析构函数的作用与调用顺序 2. 使用时机,并不是使用了继承就要把基类的析构函数变为虚函数(virtual),只有当用于多态目的时才进行一个virtual析构函数的定义. ...

  6. [转]webapi部署在IIS7.5报404的解决方案

    1.iis 目录权限设置 2.转自:http://www.cnblogs.com/youlies/p/6042169.html 在web.config添加如下节点 <system.webServ ...

  7. Web前端面试指导(十五):CSS样式-display有哪些作用?

    题目点评 其实就是要你说清楚该属性有哪些值,每个值都有什么作用,这个题目可以答得很简单,但要答全也并非是一件容易的事情. 元素默认的display值的情况如下(这个一般很少人注意这一点) block( ...

  8. 用iframe踩的坑

    1.无法监控iframe加载成功与否 经测试,火狐及chorme都不支持onerror事件,而且,不管iframe加载是否成功,都会触发onload事件. 1)通过postmessage消息提示是否加 ...

  9. easyui grid 里的可编辑text 加清空图标

    $.extend($.fn.datagrid.defaults.editors, { text: { init: function (container, options) { var _opt = ...

  10. C# 导出excel文件处理科学计数法办法

    在邦定gridview控件时在rowdatabound事件中队数据格式化 protected void DataGridView1_RowDataBound(object sender, GridVi ...