题目要求找到至少存在m个连续被染成红色的情况,相对应的,我们求至多有m-1个连续的被染成红色的情况数目,然后用总的数目将其减去是更容易的做法。

用dp来找满足条件的情况数目,,

状态:dp[i][0]和dp[i][1]分别表示第i个柱子被染成红色和蓝色的情况数目。

状态转移:dp[i][0] = dp[i-1][0]+dp[i][1]-dp[i-m][1];

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

代码如下:

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map> #define LL long long
#define eps 1e-8
#define M 100005
#define mod 1000000007 using namespace std; int n, m;
LL d[M][2];
LL _pow(int x)
{
if(x==0) return 1;
LL ans = _pow(x/2);
if(x&1) return ans*ans*2%mod;
return ans*ans%mod;
}
LL dp()
{
d[0][1] = 1;
d[0][0] = 0;
for(int i = 1; i <= n; ++i)
{
d[i][1] = (d[i-1][1]+d[i-1][0])%mod;
if(i<m)
d[i][0] = (d[i-1][1]+d[i-1][0])%mod;
else
d[i][0] = (d[i-1][1]+d[i-1][0]-d[i-m][1])%mod;
}
return (d[n][1]+d[n][0])%mod;
}
int main ()
{
while(~scanf("%d%d", &n, &m))
{
printf("%lld\n", (_pow(n)-dp()+mod)%mod);
}
return 0;
}

zoj 3725 - Painting Storages(动归)的更多相关文章

  1. [ACM] ZOJ 3725 Painting Storages (DP计数+组合)

    Painting Storages Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a straight highway with ...

  2. ZOJ - 3725 Painting Storages

    Description There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob ask ...

  3. ZOJ 3725 Painting Storages(DP+排列组合)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5048 Sample Input 4 3 Sample Output ...

  4. Painting Storages(ZOJ)

    There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob asks you to pai ...

  5. zoj 3725

    题意: n个格子排成一条直线,可以选择涂成红色或蓝色,问最少 m 个连续为红色的方案数. 解题思路: 应该是这次 ZOJ 月赛最水的一题,可惜还是没想到... dp[i] 表示前 i 个最少 m 个连 ...

  6. ZOJ-3725 Painting Storages DP

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3725 n个点排列,给每个点着色,求其中至少有m个红色的点连续的数 ...

  7. ZOJ-3725 Painting Storages 动态规划

    题意:给定一个数N,表示有N个位置,要么放置0,要么放置1,问至少存在一个连续的M个1的放置方式有多少? 分析:正面求解可能还要考虑到重复计算带来的影响,该题适应反面求解.设dp[i][j]表示到前 ...

  8. 130804组队练习赛ZOJ校赛

    A.Ribbon Gymnastics 题目要求四个点作圆,且圆与圆之间不能相交的半径之和的最大值.我当时想法很简单,只要两圆相切,它们的半径之和一定最大,但是要保证不能相交的话就只能取两两个点间距离 ...

  9. zoj 1610 Count the Colors

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=610  Count the Colors Time Limit:2000MS   ...

随机推荐

  1. erlang,elixir安装

    erlang下载地址:https://packages.erlang-solutions.com/erlang/ elixir(precompile版)下载地址:https://github.com/ ...

  2. <button> 标签 id 与 function 重复时发生的问题

    今天遇到一种情况,在调用js自定义方法的时候,总是提示“import:660 Uncaught TypeError: ... is not a function”. 仔细检查了代码,并没有问题.甚至把 ...

  3. iOS系统导航/自绘制导航路线

    系统自带导航 /** 系统自带导航 当前位置导航到目的地 1.根据目的地进行地理编码 2.把当前位置和目的地封装成MKMapItem对象 3.使用 MKMapItem openMapsWithItem ...

  4. 由Struts return SUCCESS引发的基础问题

    该问题的最初来源,是源于Struts中的 return SUCCESS; 和 return "success"; 在Struts的配置文件struts.xml我们可以找到" ...

  5. XHTML标签的嵌套规则分析

    在 XHTML 的语言里,我们都知道:ul 标签包含着 li.dl 标签包含着 dt 和 dd——这些固定标签的嵌套规则十分明确.但是,还有许多标签是独立的,它们没有被捆绑在一起,比如 h1.div. ...

  6. node服务器

    markdown support HTTP服务器 一.服务器基本方法 "use strict"; // 1.加载http模块 const http = require('http' ...

  7. php 中遍历数组时使用引用出现的问题

    今天在使用foreach遍历数组时发现,当使用&时会出现问题: $arr = array( array('id' => 100, 'error'=> 'aa'), array('i ...

  8. rdlc报表大小设置

    参考:http://stackoverflow.com/questions/427730/how-to-limit-rdlc-report-for-one-page-in-a-pdf 主要设置为:报表 ...

  9. Hibernate查询

    HIbernate查询 使用get方法 使用get方法通过持久类名和ID号查找一个对象Stu instance = (Stu) getsession() .get("com.lovo.po. ...

  10. 用Backbone.js创建一个联系人管理系统(五)

    原文: Build a Contacts Manager Using Backbone.js: Part 5 这是这系列教程最后一部分了. 之前所有的增删改都在前端完成. 这部分我们要把Contact ...