Description:

Bessie想拿\(M\) 种颜色的长为\(K\) 的图章涂一个长为\(N\) 的迷之画布。假设他选择涂一段区间,则这段区间长度必须为\(K\) ,且涂完后该区间颜色全变成图章颜色。他可以随便涂,但是最后必须把画布画满。问能有多少种最终状态,\(N\leq 10^6,M\leq 10^6,K\leq 10^6\)

Solution:

好题

告诉我了思维僵化是多么可怕

想了各种排列组合

最后看到正解直接傻逼

正着做非常不可做

考虑补集转化,求任意一段相同颜色长度都小于k的方案,再拿总方案减去即可

那个dp还是有点东西

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ls p<<1
#define rs p<<1|1
using namespace std;
typedef long long ll;
const int mxn=1e6+5,mod=1e9+7;
int n,m,k,ans,f[mxn],s[mxn]; inline int read() {
char c=getchar(); int x=0,f=1;
while(c>'9'||c<'0') {if(c=='-') f=-1;c=getchar();}
while(c<='9'&&c>='0') {x=(x<<3)+(x<<1)+(c&15);c=getchar();}
return x*f;
}
inline void chkmax(int &x,int y) {if(x<y) x=y;}
inline void chkmin(int &x,int y) {if(x>y) x=y;} int qpow(int a,int b) {
int res=1,base=a;
while(b) {
if(b&1) res=1ll*res*base%mod;
base=1ll*base*base%mod;
b>>=1;
}
return res;
} int main()
{
n=read();m=read();k=read(); int ans=qpow(m,n);
f[0]=1,s[0]=1;
for(int i=1;i<=n;++i) {
if(i<k) f[i]=1ll*f[i-1]*m%mod;
else f[i]=1ll*(s[i-1]-s[i-k]+mod)%mod*(m-1)%mod;
s[i]=(s[i-1]+f[i])%mod;
}
printf("%d\n",(ans-f[n]+mod)%mod);
return 0;
}

最新文章

  1. PHP异常处理函数set_exception_handler()的用法
  2. 与MySQL传统复制相比,GTID有哪些独特的复制姿势?
  3. 反射实现 AOP 动态代理模式(Spring AOP 的实现 原理)
  4. 从github下载某个git库的4种方法
  5. 《Play for Java》学习笔记(七)数据类型解析——Body parser
  6. loadrunner中lr_log_message和lr_output_message 的区别
  7. 你知道织梦后台安装插件时为什么会出现这个Character postion 686, 'item'&n
  8. Dubbo基本特性之泛化调用
  9. intelij IDEA破解
  10. python模块------pyinotify
  11. WPF中定时器Timer与DispatcherTimer的用法
  12. &lt;第一站&gt;人生的第一个博客
  13. JavaSE | 接口| 枚举| 注释| 异常
  14. RabbitMQ系列教程之七:RabbitMQ的 C# 客户端 API 的简介(转载)
  15. IntellJ IDEA2017 springboot2.0.2中读取配置
  16. 【oracle】入门学习(一)
  17. UVA 103
  18. leetcode-209-长度最小的子数组
  19. LVS入门篇(三)之LVS的工作模式和调度算法
  20. HDU 5167 Fibonacci 筛法+乱搞

热门文章

  1. 使用springboot actuator监控应用
  2. bootstrap的模拟单选按钮
  3. 安装和配置bazel
  4. thinkphp5.0和thinkphp3.2的区别不同之处
  5. 修改Tomcat默认连接数
  6. Windows配置Apache服务器
  7. Oracle Client(客户端) 安装与配置
  8. textarea文本域宽度和高度width及height自动适应实现代码
  9. Codeforces 342D Xenia and Dominoes 状压dp
  10. Codeforces round FF