传送门: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中final修饰参数的作用

    在方法参数前面加final关键字就是为了防止数据在方法体中被修改. 主要分两种情况:第一,用final修饰基本数据类型:第二,用final修饰引用类型. 第一种情况,修饰基本类型(非引用类型).这时参 ...

  2. 如何学习OpenStack

    转自:http://www.chenshake.com/learn-how-openstack/ 如何学习OpenStack 由于工作的关系,也招收实习生,希望可以通过实习生的培养,让他们对Opens ...

  3. Linux 文件系统大小调整

    有些使用需要进行文件系统的大小调整,比如使用LVM,或者在loopback设备上建立文件系统等,但该文件系统不是根文件系统时可以通过一下步骤,简单的进行: e2fsck -f /dev/loop0 r ...

  4. ueditor PHP版本使用方法

    1.ueditor是百度很好用的一款文本编辑器,第一次使用,在此记录使用方法. 2.从http://ueditor.baidu.com/website/download.html#ueditor下载e ...

  5. HTML5数据存储方案data与jQuery数据存储方案$.data()的区别

    我们先看下$.fn.data()的使用,这个和$.data()是不一样的,前者是和某个jquery对象相关,后者则是全局方法.主要有data()和removeData()这2个实例方法.通过下面的例子 ...

  6. 【转】OkHttp使用进阶 译自OkHttp Github官方教程

    作者:GavinCT 出处:http://www.cnblogs.com/ct2011/ 英文版原版地址 Recipes · square/okhttp Wiki 同步get 下载一个文件,打印他的响 ...

  7. 为什么canvas宽高要设置在标签内>>宽高设置在style和设置在canvas的区别

    一直很困惑为什么canvas标签和其他标签不一样,宽高需要设置在canvas标签里,设置在style里就会有问题. 纯粹个人理解,有错误欢迎指出. > 结论写在头 设置在style里有问题其实是 ...

  8. .NET开源工作流RoadFlow-Bug修改-1.8.2子流程接收者始终为发送者

    1.8.2及以前版本中子流程待办任务的处理者始终为上一步骤发送者BUG的处理: 修改类:RoadFlow.Platform.WorkFlowTask中如下图红框中的内容即可:

  9. hdu 4513 吉哥系列故事——完美队形II (manachar算法)

    吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) P ...

  10. Python爬虫教程-15-读取cookie(人人网)和SSL(12306官网)

    Python爬虫教程-15-爬虫读取cookie(人人网)和SSL(12306官网) 上一篇写道关于存储cookie文件,本篇介绍怎样读取cookie文件 cookie的读取 案例v16ssl文件:h ...