Codeforces Round #271 (Div. 2) D 简单dp
1.5 seconds
256 megabytes
standard input
standard output
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.
Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).
Input contains several test cases.
The first line contains two integers t and k (1 ≤ t, k ≤ 105), where t represents the number of test cases.
The next t lines contain two integers ai and bi (1 ≤ ai ≤ bi ≤ 105), describing the i-th test.
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
3 2
1 3
2 3
4 4
6
5
5
- For K = 2 and length 1 Marmot can eat (R).
- For K = 2 and length 2 Marmot can eat (RR) and (WW).
- For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).
- For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
题意:放置'R' 'W' W必须连续放置t个才合法 问你放置[a,b]个 共有多少种方案 具体看样例
题解:dp[i] 表示长度为i的合法方案数目 转移方程 dp[i]=dp[i-1]+dp[i-t]
#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll __int64
#define mod 1000000007
using namespace std;
int k,t;
ll sum[];
ll dp[];
int main()
{
scanf("%d %d",&k,&t);
sum[]=;
dp[]=;
for(int i=;i<t;i++){
dp[i]=;
sum[i]=(sum[i-]+dp[i])%mod;
}
for(int i=t;i<=;i++){
dp[i]=(dp[i-]+dp[i-t])%mod;
sum[i]=(sum[i-]+dp[i])%mod;
}
int a,b;
for(int i=;i<=k;i++){
scanf("%d %d",&a,&b);
printf("%I64d\n",(sum[b]-sum[a-]+mod)%mod);
}
return ;
}
Codeforces Round #271 (Div. 2) D 简单dp的更多相关文章
- Codeforces Round #302 (Div. 2) C 简单dp
C. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #271 (Div. 2) D.Flowers DP
D. Flowers We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, ...
- Codeforces Round #271 (Div. 2)题解【ABCDEF】
Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- Codeforces Round #271 (Div. 2) F ,E, D, C, B, A
前言:最近被线段树+简单递推DP虐的体无完肤!真是弱! A:简单题,照着模拟就可以,题目还特意说不用处理边界 B:二分查找即可,用lower_lound()函数很好用 #include<stri ...
- Codeforces Round #278 (Div. 1) B - Strip dp+st表+单调队列
B - Strip 思路:简单dp,用st表+单调队列维护一下. #include<bits/stdc++.h> #define LL long long #define fi first ...
- Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)
题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...
- Codeforces Round #271 (Div. 2) E. Pillars 线段树优化dp
E. Pillars time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #271 (Div. 2) D Flowers【计数dp】
D. Flowers time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input ...
随机推荐
- 《Cocos2d-x游戏开发实战精解》学习笔记1--在Cocos2d中显示图像
Cocos2d-x中的图像是通过精灵类来显示的.在Cocos2d-x中游戏中的每一个角色.怪物.道具都可以理解成是一个精灵,游戏背景作为一种特殊的单位将其理解成是一个精灵也没有什么不妥.在源文件本章目 ...
- ShipStation Now Uses AWS And Amazon Fulfillment To Automatically Ship From eBay, Sears And Other Marketplaces
ShipStation today unveiled a first-of-its-kind service to leverage Amazon Web Services and Amazon.co ...
- 使用 Sublime Text 做 Javascript 编辑器 - 集成 JSHint 问题检测工具
JSHint(jshint.com)是 Javascritp 代码质量工具,可以帮助开发人员发现 Javascript 代码中的错误和潜在的问题.jshint.com 是一个在线编辑器,我们可以为 S ...
- 大数据-spark-hbase-hive等学习视频资料
不错的大数据spark学习资料,连接过期在评论区评论,再给你分享 https://pan.baidu.com/s/1ts6RNuFpsnc39tL3jetTkg
- hadoop HA sshfen切换隔离时无法跳转ssh: bash: fuser: 未找到命令
在zkfc的日志里面,有一个warn:PATH=$PATH:/sbin:/usr/sbin fuser -v -k -n tcp 8090 via ssh: bash: fuser: 未找到命令原因是 ...
- xpath获取同级元素
XPath轴(XPath Axes)可定义某个相对于当前节点的节点集: 1.child 选取当前节点的所有子元素 2.parent 选取当前节点的父节点 3.descendant 选取当前节点的所有后 ...
- loadrunner11--基础使用
每次开启电脑都需要破解一次Lr,汉化版的有问题,建议使用英文版的.我测试的环境是Windows7+IE8+LR11.(在Windows10上试过,谷歌和IE11都不能正常运行),以下我会具体来操作,最 ...
- Longge's problem(欧拉函数应用)
Description Longge is good at mathematics and he likes to think about hard mathematical problems whi ...
- Requests库与HTTP协议
了解HTTP协议 请求与响应模式的协议: 用户提出对URL(用来定位网络中的资源位置)地址数据的操作请求,服务器给予相应. 无状态的应用层协议:两次请求之间不会互相影响. HTTP协议支持的请求种类: ...
- 中国剩余定理---FZU 1402 猪的安家
J - 猪的安家 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...