题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3725

  n个点排列,给每个点着色,求其中至少有m个红色的点连续的数目。f[i]表示前i个点至少有m个连续红色的个数,则f[i]=f[i-1]*2+2^(i-m-1)-f[i-m-1]。

 //STATUS:C++_AC_120MS_1784KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef long long LL;
typedef unsigned long long ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End LL f[N],b[N];
int n,m; int main()
{
// freopen("in.txt","r",stdin);
int i,j,k;
b[]=;
for(i=;i<N;i++)b[i]=*b[i-]%MOD;
while(~scanf("%d%d",&n,&m))
{
for(i=;i<m;i++)f[i]=;
f[m]=,f[m+]=;
for(i=m+;i<=n;i++){
f[i]=(*f[i-]+b[i-m-]-f[i-m-])%MOD;
}
printf("%lld\n",(f[n]+MOD)%MOD);
}
return ;
}

ZOJ-3725 Painting Storages DP的更多相关文章

  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(DP+排列组合)

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

  3. ZOJ - 3725 Painting Storages

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

  4. zoj 3725 - Painting Storages(动归)

    题目要求找到至少存在m个连续被染成红色的情况,相对应的,我们求至多有m-1个连续的被染成红色的情况数目,然后用总的数目将其减去是更容易的做法. 用dp来找满足条件的情况数目,, 状态:dp[i][0] ...

  5. ZOJ Problem Set - 3822Domination(DP)

    ZOJ Problem Set - 3822Domination(DP) problemCode=3822">题目链接 题目大意: 给你一个n * m的棋盘,每天都在棋盘上面放一颗棋子 ...

  6. Painting Storages(ZOJ)

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

  7. zoj 3725

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

  8. zoj 3537 Cake 区间DP (好题)

    题意:切一个凸边行,如果不是凸包直接输出.然后输出最小代价的切割费用,把凸包都切割成三角形. 先判断是否是凸包,然后用三角形优化. dp[i][j]=min(dp[i][j],dp[i][k]+dp[ ...

  9. ZOJ 3623 Battle Ships DP

    B - Battle Ships Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Subm ...

随机推荐

  1. 创建Mysql

    CREATE DATABASE IF NOT EXISTS yiya DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

  2. 一步步学习NHibernate(7)——HQL查询(1)

    请注明转载地址:http://www.cnblogs.com/arhat 从本章开始,老魏带着大家来学习一下HQL语句.HQL语句NHibernate为我们提供的一种功能比较强大的查询语句,这个HQL ...

  3. UIApplication sharedApplication 的常用使用方法-b

    下面是这个类的一些功能:1.设置icon上的数字图标 //设置主界面icon上的数字图标,在2.0中引进, 缺省为0 [UIApplicationsharedApplication].applicat ...

  4. iOS 后台运行实现 --备用

    文一 我从苹果文档中得知,一般的应用在进入后台的时候可以获取一定时间来运行相关任务,也就是说可以在后台运行一小段时间. 还有三种类型的可以运行在后以,1.音乐2.location 3.voip 文二 ...

  5. C3p0的参数设置

    C3p0的参数设置:ComboPooledDataSource和BasicDataSource一样提供了一个用于关闭数据源的close()方法,这样我们就可以保证Spring容器关闭时数据源能够成功释 ...

  6. c++ 输入一行字符串

    ]; //cin>>str1; 方式1 不能统计(录入)空格后的字符 cin.); //方式2 能统计空格后输入的字符 按回车键输入结束 get()会将换行符保存在序列里 //gets(s ...

  7. Eclipse 启动问题:'Initilizing Java Tooling' has encountered a problem(。。。)

    一.问题描述: . 二.分析及解决 ...

  8. CSS display 属性详解

    定义display 属性设置是否及如何显示元素. 继承性: No 说明 这个属性用于定义建立布局时元素生成的显示框类型.对于 HTML 等文档类型,如果使用 display 不 谨慎会很危险,因为可能 ...

  9. java区分大小写,使用TAB进行缩进,public类名只能有一个,而且文件名与类名保持一致.

    java的类必须大写 java区分大小写,使用TAB进行缩进,public类名只能有一个,而且文件名与类名保持一致. 在dos用上下箭头,调用已用过的命令

  10. 汇编 db,dw,dd的区别

    db定义字节类型变量,一个字节数据占1个字节单元,读完一个,偏移量加1 dw定义字类型变量,一个字数据占2个字节单元,读完一个,偏移量加2 dd定义双字类型变量,一个双字数据占4个字节单元,读完一个, ...