题目链接: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. less的使用方法

    LESS学习 1.变量 我们可以把一个css样式的值赋给一个参数,然后再设置样式的时候只需要设置这个参数名,如果要修改,就改参数的值就可以了. demo.html <!DOCTYPE html& ...

  2. Oracle索引扫描

    Oracle索引扫描:先通过index查找到索引的值,并根据索引的值对应的rowid值(对于非唯一索引可能返回多个rowid值)直接从表中得到具体的数据.一个rowid唯一的表示一行数据,该行对应的数 ...

  3. MFC应用程序向导生成的文件

    比方说我们用Visio Studio创建了一个MFC应用程序,名称为Mysdi.在创建这个项目的时候,默认的会生成许多类和文件,就关于这些文件的内容和要点展开以下论述. 框架窗口类头文件 向导为项目M ...

  4. CODEVS 3943 数学奇才琪露诺

    [题目描述 Description] 作为上白泽慧音老师的出色弟子,数学奇才琪露诺在算术方面有很深的造诣.今天,codevs有幸请到了这位数学界的奇葩作为本场考试的第一题主考官. 琪露诺喜欢0-9之间 ...

  5. how to run demo city bars using sencha architect

    1. create a project using city bars template in sencha architect 2. save your project name as CityBa ...

  6. hibernate持久化操作注意

    15:05 2014/5/21 1.设置lazy为false可以立即加载配合get,lazy默认true,配合load使用. 2.把pojo类定义为final的类.为最终就可以不使用代理 3.pojo ...

  7. final, finally 和finalize的区别

    final 修饰符(关键字) 如果一个类被声明为final,意味着它不能再派生新的子类,不能作为父类被继承.因此一个类不能及被声明为abstract,又被声明为final的.将变量或方法声明为fina ...

  8. 2014年50个程序员最适用的免费JQuery插件

    有用的jQuery库是设计师和开发者之间一个非常熟悉的短语.这是现在互联网中最流行的JavaScript函数库之一.每个设计师和开发人员都应该知道它的重要性,而且熟悉它的功能和特点. jQuery几乎 ...

  9. Cygwin环境编译/usr/include/sys/_types.h:72:20: 致命错误:stddef.h:can not found

    环境介绍: win7_x64 +Cygwin64 gcc :4.8.2 g++:4.8.1 编译 c++的helloworld.cpp 一直失败! 代码如下: #include <iostrea ...

  10. bitset学习小记

    Cplusplus官网的资料: http://www.cplusplus.com/reference/bitset/bitset/ http://www.cplusplus.com/reference ...