https://codeforces.com/problemset/problem/474/D

这道题挺好的,思路是这样。

我们要找一个01串,其中0的段要被划分为若干个连续k的0。

我们设想一个长度为n的合法串是怎么被构造出来的,要么是上一个合法串后面直接连接1,要么是上一个合法串后面连接k个连续的0,那么每个0一一对应于一段连续的0。

所以dp[i]=dp[i-1]+dp[i-k]。

想出来就觉得不难了。

#include<bits/stdc++.h>
using namespace std;
#define ll long long int t,k;
int a,b; int dp[];
int sum[]; int main(){
scanf("%d%d",&t,&k);
for(int i=;i<=k-;i++){
dp[i]=;
}
dp[k]=;
for(int i=k+;i<=;i++){
dp[i]=(dp[i-]+dp[i-k])%;
} for(int i=;i<=;i++){
sum[i]=(sum[i-]+dp[i])%;
} for(int i=;i<t;i++){
scanf("%d%d",&a,&b);
printf("%d\n",(sum[b]-sum[a-]+)%);
}
}

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)

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

  3. Codeforces 474D Flowers dp(水

    题目链接:点击打开链接 思路: 给定T k表示T组測试数据 每组case [l,r] 有2种物品a b.b物品必须k个连续出现 问摆成一排后物品长度在[l,r]之间的方法数 思路: dp[i] = d ...

  4. Codeforces - 702A - Maximum Increase - 简单dp

    DP的学习计划,刷 https://codeforces.com/problemset?order=BY_RATING_ASC&tags=dp 遇到了这道题 https://codeforce ...

  5. Codeforces 1108D - Diverse Garland - [简单DP]

    题目链接:http://codeforces.com/problemset/problem/1108/D time limit per test 1 secondmemory limit per te ...

  6. codeforces 474D.Flowers 解题报告

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

  7. Codeforces 474D Flowers 动态规划法

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

  8. Codeforces - 1081C - Colorful Bricks - 简单dp - 组合数学

    https://codeforces.com/problemset/problem/1081/C 这道题是不会的,我只会考虑 $k=0$ 和 $k=1$ 的情况. $k=0$ 就是全部同色, $k=1 ...

  9. Codeforces - 909C - Python Indentation - 简单dp

    http://codeforces.com/problemset/problem/909/C 好像以前做过,但是当时没做出来,看了题解也不太懂. 一开始以为只有上面的for有了循环体,这里的state ...

随机推荐

  1. iPhone 适配之路

    (1)1x时代 2007年,初代iPhone公布,屏幕的宽高是320*480像素.这个分辨率一直到iPhone3GS也保持不变. 那时编写iOS的App应用程序.仅仅支持绝对定位. 比方一个butto ...

  2. winform中使用ReportViewer的时候,找不到报表数据面板.

    最近在做winform的报表项目,看人家教程里都有报表数据面板,可我的怎么都找不到,我的是VS2012,最后终于找到,首先必须在报表设计TAB上(选中它),然后选择视图->报表数据

  3. 【Leetcode】经典的Jump Game in JAVA

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  4. UUID GUID

    http://baike.baidu.com/link?url=xkck9gR5bzOx0oBKP1qNJwGGq3IO56V4i8cg9zTSpSDMVBMA0F7jr0AdkQTGyk7F0FGj ...

  5. 理解OpenStack认证:Keystone PKI

    原文链接: https://www.mirantis.com/blog/understanding-openstack-authentication-keystone-pki/ The latest ...

  6. openssl 再爆惊天漏洞及紧急修复指南

    openssl 又摊上大事了,2014年6月5日,SSL/TLS Man-in-the-Middle Vulnerability 该漏洞使得攻击者能够拦截恶意中间节点加密和解密数据.同一时候强迫使用弱 ...

  7. Andriod Atom x86模拟器启动报错。

    用Inter Atom模式的Android模拟器启动报一下错误: Starting emulator for AVD 'new' emulator: ERROR: x86 emulation curr ...

  8. android5.0(Lollipop) BLE Peripheral牛刀小试

    转载请表明作者:http://blog.csdn.net/lansefeiyang08/article/details/46468743 知道Android L对蓝牙对了一些改进.包含加入A2dp s ...

  9. Flume接收器组的指数退避上限

    指数退避 agent.sinkgroups.sg1.sinks=k1,k2,k3agent.sinkgroups.sg1.processor.type=failoveragent.sinkgroups ...

  10. Sequelize入门一

    最近刚开始接触Sequelize,当中遇到不少坑,所以想写篇Sequelize入门和大家分享,避免有道友和我一样爬坑. 学习sequelize的初衷是想解决SQL注入,它支持MySQL, SQLite ...