[USACO18JAN]Stamp Painting
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;
}
[USACO18JAN]Stamp Painting的更多相关文章
- luogu4187 [USACO18JAN]Stamp Painting (dp)
可以发现,只要存在连续k个相同的,这个情况就一定是合法情况 然而这个不太好算,我们算不存在k个相同的,然后用$m^n$把它减掉 设f[i]为前i个,没有连续k个的 显然$f[i]=m^i ,i< ...
- 2018.10.25 洛谷P4187 [USACO18JAN]Stamp Painting(计数dp)
传送门 其实本来想做组合数学的2333. 谁知道是道dpdpdp. 唉只能顺手做了 还是用真难则反的思想. 这题我们倒着考虑,只需要求出不合法方案数就行了. 这个显然是随便dpdpdp的. f[i]f ...
- BZOJ5190 Usaco2018 Jan Stamp Painting(动态规划)
可以大胆猜想的一点是,只要有不少于一个长度为k的颜色相同子串,方案就是合法的. 直接算有点麻烦,考虑减去不合法的方案. 一个正(xue)常(sha)的思路是枚举序列被分成的段数,问题变为用一些1~k- ...
- luogu4187
P4187 [USACO18JAN]Stamp Painting 样例 input3 2 2output6 input6 10 5output190 sol:首先可以发现,对于合法的序列,只要有一串至 ...
- CF448C Painting Fence (分治递归)
Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...
- [译]使用Continuous painting mode来分析页面的绘制状态
Chrome Canary(Chrome “金丝雀版本”)目前已经支持Continuous painting mode,用于分析页面性能.这篇文章将会介绍怎么才能页面在绘制过程中找到问题和怎么利用这个 ...
- Codeforces Round #353 (Div. 2)Restoring Painting
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was sto ...
- [BTS] Faulting application name: BTSNTSvc.exe, version: 3.9.469.0, time stamp: 0x4c547e09
Log Name: ApplicationSource: Application ErrorDate: 8/22/2013 1:28:35 AMEvent ID: 1000Task Category: ...
- hdu-4810 Wall Painting(组合数学)
题目链接: Wall Painting Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
随机推荐
- 设置IDEA中的web
- Python迷宫游戏(基础版)
# 画地图map_data = [ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 1, 0, 0, 0, ...
- Linux桌面环境安装matlab并创建快捷方式
安装matlab sudo mkdir -p /mnt/matlab sudo mount -t auto -o loop /home/chris/Downloads/2016b_linux/R201 ...
- EF Core MYSQL 生成表映射配置问题
Model表 public class Goods { public string ID { get; set; } public string CreatedBy { get; set; } pub ...
- GZipStream 压缩与解压数据
简介:此类表示 GZip 数据格式,它使用无损压缩和解压缩文件的行业标准算法.这种格式包括一个检测数据损坏的循环冗余校验值.GZip 数据格式使用的算法与 DeflateStream 类的算法相同,但 ...
- Haproxy重刷一次
centos上,yum安装,完全无难度. 只是设置时,要注意一下跳转,和nginx规则差不多. https://blog.csdn.net/qq_28710983/article/details/82 ...
- photoshop CC智能切图
网页设计在技术层面上,第一步是美工做出网页效果图,第二步就是网页前端进行网页切图.网页切图工具常用的有fireworks.PS,这里使用PS进行网页切图. 我们通过设计稿,得到我们想要的产出物(如.p ...
- Python学习(二十) —— 前端之CSS
转载自http://www.cnblogs.com/liwenzhou/p/7999532.html 一.CSS介绍 CSS(Cascading Style Sheet,层叠样式表)定义如何显示HTM ...
- docker保存、载入、导出、导入
保存和载入 拿到CONTAINER ID docker ps -a 通过容器id生成镜像dockerlinuxdemoweb:update docker commit b33633d12871 doc ...
- .netcore加入APM系统 SkyWalking
安装环境:windows 2016 必要条件: JDK8+ Elasticsearch 5.x(注:目前不支持es6) 8080,10800,11800,12800 端口不被占用 下载skywalki ...