Codeforces 474D Flowers
http://codeforces.com/problemset/problem/474/D
思路:F[i]=F[i-1]+(i>=K)F[i-k]
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
const int Mod=;
int K,sum[],f[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
void init(){
f[]=;
for (int i=;i<=;i++){
f[i]=(f[i-])%Mod;
if (i>=K)
f[i]=(f[i]+f[i-K])%Mod;
}
for (int i=;i<=;i++)
sum[i]=(sum[i-]+f[i])%Mod;
}
int main(){
int T=read();K=read();
init();
while (T--){
int l=read(),r=read();
printf("%d\n",((sum[r]-sum[l-])%Mod+Mod)%Mod);
}
return ;
}
Codeforces 474D Flowers的更多相关文章
- Codeforces 474D Flowers 动态规划法
话说好久没写算法代码了,工作了有点忙的了.只是算法始终是我的挚爱,故此还是尽量抽时间和挚爱来个约会. Codeforces的题目是最适合练手的了,以下是一道不算难的动态规划法题目.先上题: D. Fl ...
- Codeforces 474D Flowers (线性dp 找规律)
D. Flowers time limit per test:1.5 seconds memory limit per test:256 megabytes We saw the little gam ...
- codeforces 474D.Flowers 解题报告
题目链接:http://codeforces.com/problemset/problem/474/D 题目意思:Marmot 吃两种类型的花(实在难以置信呀--):red 或者 white,如果要吃 ...
- Codeforces - 474D - Flowers - 构造 - 简单dp
https://codeforces.com/problemset/problem/474/D 这道题挺好的,思路是这样. 我们要找一个01串,其中0的段要被划分为若干个连续k的0. 我们设想一个长度 ...
- Codeforces 474D Flowers(DP)
题目链接 非常简单的一道dp题,通过O(n)的预处理来使查询变为O(1). 主要的坑在于取模后的dp数组的前缀和再相减可能得到负数,导致无法得到某一区间和的取模. 解决方法:(a-b)%mo==(a% ...
- Codeforces 474D Flowers dp(水
题目链接:点击打开链接 思路: 给定T k表示T组測试数据 每组case [l,r] 有2种物品a b.b物品必须k个连续出现 问摆成一排后物品长度在[l,r]之间的方法数 思路: dp[i] = d ...
- 【Codeforces 474D】Flowers
[链接] 我是链接,点我呀:) [题意] 让你吃东西 B食物一次必须要吃连续k个 但是对A食物没有要求 问你有多少种吃n个食物的方法(吃的序列) [题解] 设f[i]表示长度为i的吃的序列且符合要求的 ...
- CodeForces - 474D (dp)
题目:https://vjudge.net/contest/326867#problem/B 题意:有很多个蛋糕,现在你有两种吃蛋糕的吃法,一次吃一个,定为A,一次吃k个定为B,然后问你吃m个蛋糕有多 ...
- codeforces474D
Flowers CodeForces - 474D 话说某个幸运的小伙伴X拿到了kevin女神送的蛋糕,然而他的吃法非常奇特,他独创了两种吃蛋糕的办法:一.一次吃一整个蛋糕:二.一次吃k个蛋糕. 那么 ...
随机推荐
- 改进RazorPad
从Git 上下载了作者的源码后,感觉用起来挺别扭,而且还要BUG............ 经过“篡改”后,好用多了,呵呵..
- Json帮助类以及如何使用
首先要添加引用System.Runtime.Serialization. public class JSONHelper { public static string Serialize<T&g ...
- 详解HashMap的内部工作原理
本文将用一个简单的例子来解释下HashMap内部的工作原理.首先我们从一个例子开始,而不仅仅是从理论上,这样,有助于更好地理解,然后,我们来看下get和put到底是怎样工作的. 我们来看个非常简单的例 ...
- poj 2441 Arrange the Bulls(状态压缩dp)
Description Farmer Johnson's Bulls love playing basketball very much. But none of them would like to ...
- NetAnalyzer笔记 之 八 NetAnalyzer2016使用方法(2)
[创建时间:2016-05-06 22:07:00] NetAnalyzer下载地址 在写本篇的时候,NetAnalyzer 3.1版本已经发布,所以本篇就以最新版本的为例继续使用,并且顺带说明一下, ...
- [原创]Web前端开发——让ie 7 8支持表单的placeholder属性
今天在写页面的时候,测试低版本浏览器时,发现input写的placeholder显示的是空白,所以特意写了一个普遍试用的方法来让低版本浏览器支持这个属性. 博主建了一个技术共享qq群:,因为目前人数还 ...
- wlan0 Interface doesn't support scanning : Device or resource busy
Problem: wlan0 Interface doesn't support scanning : Device or resource busy. Solved Way: sudo ifcong ...
- mysql判断某个字符串是否包含另一个
like SELECT * FROM wx_webauth_userinfo where city LIKE "%台%";"; 结果: 函数find_in_set(str ...
- C语言随记-1
涉及指针.数组.函数指针 几种声明形式 int *a[5]; // a是一个有5个元素的数组,每个元素是整数类型指针(int *) int *a[] = {0x100, 0x104, 0x108, 0 ...
- jquery之null的数组
去掉null的数组 function ClearNullArr(arr) { for (var i = 0; i < arr.length; i++) { if(arr[ ...