题目链接:点击打开链接

思路:

给定T k表示T组測试数据

每组case [l,r]

有2种物品a b。b物品必须k个连续出现

问摆成一排后物品长度在[l,r]之间的方法数

思路:

dp[i] = dp[i-1]+dp[i-k];

#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
template <class T>
inline bool rd(T &ret) {
char c; int sgn;
if(c=getchar(),c==EOF) return 0;
while(c!='-'&&(c<'0'||c>'9')) c=getchar();
sgn=(c=='-')?-1:1;
ret=(c=='-')? 0:(c-'0');
while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
ret*=sgn;
return 1;
}
template <class T>
inline void pt(T x) {
if (x < 0) {
x = -x;
putchar('-');
}
if(x>9) pt(x/10);
putchar(x%10+'0');
}
/////////////////////////
const int N = 100000 + 2;
const int mod = 1000000007;
ll d[N], sum[N];
int main() {
int cas, K, l, r;
rd(cas); rd(K);
d[0] = 1;
for (int i = 1; i < N; ++i) {
d[i] = d[i - 1];
if (i >= K)
d[i] += d[i - K];
d[i] %= mod;
}
sum[0] = 1;
for (int i = 1; i < N; ++i) {
sum[i] = sum[i - 1] + d[i];
sum[i] %= mod;
}
while (cas -- > 0) {
rd(l); rd(r);
pt(((sum[r]-sum[l-1]) % mod + mod) % mod);
putchar('\n');
}
return 0;
}

Codeforces 474D Flowers dp(水的更多相关文章

  1. Codeforces 474D Flowers (线性dp 找规律)

    D. Flowers time limit per test:1.5 seconds memory limit per test:256 megabytes We saw the little gam ...

  2. Codeforces - 474D - Flowers - 构造 - 简单dp

    https://codeforces.com/problemset/problem/474/D 这道题挺好的,思路是这样. 我们要找一个01串,其中0的段要被划分为若干个连续k的0. 我们设想一个长度 ...

  3. Codeforces 474D Flowers(DP)

    题目链接 非常简单的一道dp题,通过O(n)的预处理来使查询变为O(1). 主要的坑在于取模后的dp数组的前缀和再相减可能得到负数,导致无法得到某一区间和的取模. 解决方法:(a-b)%mo==(a% ...

  4. codeforces 474D.Flowers 解题报告

    题目链接:http://codeforces.com/problemset/problem/474/D 题目意思:Marmot 吃两种类型的花(实在难以置信呀--):red 或者 white,如果要吃 ...

  5. Codeforces 474D Flowers 动态规划法

    话说好久没写算法代码了,工作了有点忙的了.只是算法始终是我的挚爱,故此还是尽量抽时间和挚爱来个约会. Codeforces的题目是最适合练手的了,以下是一道不算难的动态规划法题目.先上题: D. Fl ...

  6. Codeforces 474D Flowers

    http://codeforces.com/problemset/problem/474/D 思路:F[i]=F[i-1]+(i>=K)F[i-k] #include<cstdio> ...

  7. Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题

    除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...

  8. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

  9. [poj2247] Humble Numbers (DP水题)

    DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...

随机推荐

  1. 平时的笔记02:处理mp3

    #! /usr/bin/env python # # mutagen aims to be an all purpose media tagging library # Copyright (C) 2 ...

  2. nginx 采用https 协议通信配置

    在网络通信中,使用抓包软件可以对网络请求进行分析,并进行重放攻击,重放攻击的解决方案一般是使用一个变化的参数,例如RSA加密的时间戳,但考虑到网络传输时延,时间戳需要有一定的误差容限,这样仍然不能从根 ...

  3. ci 笔记

    一.CI的HelloWorld! 注意:CI禁止直接通过文件目录来访问控制器. ./application/controllers/hello.php 1 <?php 2 //放止用户直接通过路 ...

  4. linux下查看文件及目录个数

    linux下查看文件及目录个数1.查看当前文件和目录总数(不包括子目录):ls -l | wc -l 2.查看当前目录下文件个数(不包括子目录):ls -l |grep "^-"| ...

  5. UISegmentedControl判断点击第几项

    UISegmentedControl 关于UISegmentedControl判断当前点击的是第几项,找了很久,终于再老外的博客上找到了,在委托中 UISegmentedControl *Seg=se ...

  6. 部分GDAL工具功能简介

    主要转自http://blog.csdn.net/liminlu0314?viewmode=contents 部分GDAL工具功能简介 gdalinfo.exe 显示GDAL支持的各种栅格文件的信息. ...

  7. SQLSERVER执行时间统计工具SQLQueryStress

    有时候需要检测一下SQL语句的执行时间,相信大家都会用SET STATISTICS TIME ON开关打开SQLSERVER内置的时间统计 SET STATISTICS TIME ON 不过这款小工具 ...

  8. 怎样给win7系统硬盘分区

    怎样给win7系统硬盘分区 步骤 一.鼠标右击“计算机” 二.选择“管理”标签 三.打开“计算机管理”窗口 四.选择“磁盘“>>”存储管理“,打开”磁盘管理“页面 如图: 五.右键单击选择 ...

  9. 改变navigationbar的底部线条颜色

    [[UINavigationBar appearance] setBackgroundImage:[UIImage new]forBarMetrics:UIBarMetricsDefault]; CG ...

  10. AC自动机(模板)

    #include <cstdio> #include <cstring> #include <iostream> #include <cstdlib> ...