题目大意:

1*n的格子 可以用m种颜色涂色

已知从第2开始到第n个格子 有k个格子与其左边的格子颜色不同

求涂色的方案数

相当于把n个格子分成k+1份

可以递推出分成k+1份的不同的方案数(其实递推公式就是组合数递推公式)

也可以隔板法直接求C(n-1,k)

已知所有分法后 直接涂色 那么第一份可以涂m种颜色

而第二块开始只能涂m-1种 因为要和左边那一份的颜色不同

所以C(n-1,k)*m*(m-1)^k

一定要注意取模问题 乘法要取模

递推时的加法也要取模啊 太粗心了 赛后递推加个取模就过了

#include <bits/stdc++.h>
#define LL long long
#define mod 998244353
using namespace std;
LL n,m,k;
LL dp[][];
LL mod_pow(LL x,LL n) {
LL res=1LL;
while(n) {
if(n&) res=res*x%mod;
x=x*x%mod;
n>>=;
} return res%mod;
}
int main()
{
while(~scanf("%I64d%I64d%I64d",&n,&m,&k)) {
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++) dp[i][]=1LL;
for(int i=;i<=n;i++)
for(int j=;j<i && j<=k;j++)
dp[i][j]=(dp[i-][j]+dp[i-][j-])%mod;
LL one=1LL*m*mod_pow(m-1LL,k)%mod;
printf("%I64d\n",one*dp[n][k]%mod);
} return ;
}

Avito Cool Challenge 2018 C - Colorful Bricks的更多相关文章

  1. Avito Cool Challenge 2018 C. Colorful Bricks 【排列组合】

    传送门:http://codeforces.com/contest/1081/problem/C C. Colorful Bricks time limit per test 2 seconds me ...

  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. PAT甲级——A1143 LowestCommonAncestor【30】

    The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U ...

  2. Linux 常用指令总结

    一. 与时间有关的参数: 1.find 基本语法参数如下: find [PATH] [option] [action] -mtime n : n为数字,意思为在n天之前的“一天内”被更改过的文件: - ...

  3. ajaxfileupload上传文件出现SyntaxError:unexpected token <错误

    function ajaxFileUpload() { $.ajaxFileUpload ( { url: uri, secureuri: false, fileElementId: 'upFile' ...

  4. mysql 个人博客应用的建表和相关查询

    一.建表 用户表tb_user create table if not exists tb_user( user_id int auto_increment, ) not null, user_pas ...

  5. [轉]Reverse a singly linked list

    Reverse a singly linked list  http://angelonotes.blogspot.tw/2011/08/reverse-singly-linked-list.html ...

  6. Jsoup爬虫任务总结

    这两周由于公司需要大量数据爬取进数据库给用户展示素材,在不停的做爬虫工作,现在总算基本完成就剩清理数据的工作: 公司有一个采集器管理后台的项目,可以直接把爬虫代码打包成jar导入进去设置定时参数即可: ...

  7. 自定义servlet重写doGet或者doPost方法时,405 method not allowed

    自定义servlet public class TestServlet extends HttpServlet { @Override protected void doGet(HttpServlet ...

  8. Input标签文件上传,使用详解

    1.html添加标签按钮 <button ion-button (click)="selectVideo()">添加</button> <input ...

  9. JNI中修改(基本类型)参数并返回到Java层使用

    最近在JNI相关项目中遇到一个问题:在Java层传入多个int类型的参数,在jni层修改参数值或地址之后重新返回到Java层.这应该算是基本知识了,尤其是基本类型的参数往往看似简单,所以在之前学习jn ...

  10. 2018-3-5-安装-pip

    title author date CreateTime categories 安装 pip lindexi 2018-3-5 19:4:4 +0800 2018-03-05 18:57:15 +08 ...