[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 ...
随机推荐
- angular-cli ng build 打包完成后 打开文件显示空白
将index.html 里面的<base href="/"> 改为<base href="./"> 前面加一个 点 就好了,然后再次打包 ...
- MyBatis - 10.MyBatis扩展
1.PageHelpler分页插件使用 官方文档:中文 1.1 引入插件 1.1.1 引入的jar pagehelper-5.1.6.jar jsqlparser-1.2.jar 1.1.2 mave ...
- Android 敏感权限申请
动态权限管理是Android6.0(Build.VERSION_CODES.M = Api23)推出的,提醒用户当前APP所需要的权限,防止滥用.这些权限一般分为三种:(1)普通权限:直接manife ...
- RSA javascript加密 lua解密
一个在线RSA非对称加密解密,可以用这个地址生成公钥和私钥 https://blog.zhengxianjun.com/online-tool/rsa/ javascript加密 jsencrypt. ...
- 解决Python安装模块出错 ImportError: No module named setuptools
1.下载ez_setup.py文件 下载地址:https://bootstrap.pypa.io/ez_setup.py 百度地址:http://pan.baidu.com/s/1jIgMO9w 2. ...
- loadrunner下的putty和plink
loadrunner中是有集成plink和putty的,难怪可以通过监控机监控linux上的负载情况呢,可以通过这个命令来进行访问:C:\Program Files\Mercury\LoadRunne ...
- 常见内网IP段
以下IP段为内网IP段: 192.168.0.0 - 192.168.255.255 172.16.0.0 - 172.31.255.255 10.0.0.0 - 10.255.255.255
- Python Web开发问题收集(二)
- python---初始sqlite3
***sqllite不需要单独安装,python2.5以上自带的! ***官方中文文档:https://docs.python.org/2/library/sqlite3.html ***SQLite ...
- Codeforces 542D Superhero's Job 数论 哈希表 搜索
原文链接https://www.cnblogs.com/zhouzhendong/p/CF542D.html 题目传送门 - CF542D 题目传送门 - 51Nod1477 题意 定义公式 $J(x ...