题目描述

Bessie has found herself in possession of an

NN

-unit long strip of canvas (

1N1061 \leq N \leq 10^6

), and she intends to paint it. However, she has been unable to acquire paint brushes. In their place she has

MM

rubber stamps of different colors (

1M1061 \leq M \leq 10^6

), each stamp

KK

units wide (

1K1061 \leq K \leq 10^6

). Astounded by the possibilities that lie before her, she wishes to know exactly how many different paintings she could conceivably create, by stamping her stamps in some order on the canvas.

To use a stamp, it must first be aligned with exactly

KK

neighboring units on the canvas. The stamp cannot extend beyond the ends of the canvas, nor can it cover fractions of units. Once placed, the stamp paints the

KK

covered units with its color. Any given stamp may be used multiple times, once, or even never at all. But by the time Bessie is finished, every unit of canvas must have been painted at least once.

Help Bessie find the number of different paintings that she could paint, modulo

109+710^9 + 7

. Two paintings that look identical but were painted by different sequences of stamping operations are counted as the same.

For at least 75% of the input cases,

N,K103N,K \leq 10^3

.

输入输出格式

输入格式:
The first and only line of input has three integers,

NN

,

MM

, and

KK

. It is guaranteed that

KNK \leq N

.

输出格式:
A single integer: the number of possible paintings, modulo

109+710^9 + 7

.

输入输出样例

输入样例#1: 复制
输出样例#1: 复制

说明

If the two stamps have colors A and B, the possible paintings are AAA, AAB, ABB, BAA, BBA, and BBB.

动态规划计数dp 每次可以用长度为k的一块覆盖线段覆盖出来都是相同的颜色现在求 方案数是多少 那么可以感知到我这样做的话最后的序列里一定有一块长度为k的块那么我就这么dp即可 当时想的时候在这里我也和zhx巨佬一样想不动了 后来正解我也想了 很久 正解:既然正着不好考虑就倒着考虑即可 就直接考虑 计算不存在k长度连续区间相同的方案数 那么设dp[i]表示长度为i的这个方案数即可 那么dp[i]=$\sum_{j=1}^{k-1}(m-1)*dp[j]$ 这样相当于枚举我当前第i号位置最后末端颜色相同那么为了避免出现连续的相同的我需要使得他们和i-j的前一个不相同 所以乘(m-1)即可关于这个dp 做一个后缀和累加下即可

 

 


elijahqi

退役了 现在在商院 偶尔打CF,有时有ACM regional也去玩一下

发表评论