zoj 3725 - Painting Storages(动归)
题目要求找到至少存在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(动归)的更多相关文章
- [ACM] ZOJ 3725 Painting Storages (DP计数+组合)
Painting Storages Time Limit: 2 Seconds Memory Limit: 65536 KB There is a straight highway with ...
- ZOJ - 3725 Painting Storages
Description There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob ask ...
- ZOJ 3725 Painting Storages(DP+排列组合)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5048 Sample Input 4 3 Sample Output ...
- Painting Storages(ZOJ)
There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob asks you to pai ...
- zoj 3725
题意: n个格子排成一条直线,可以选择涂成红色或蓝色,问最少 m 个连续为红色的方案数. 解题思路: 应该是这次 ZOJ 月赛最水的一题,可惜还是没想到... dp[i] 表示前 i 个最少 m 个连 ...
- ZOJ-3725 Painting Storages DP
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3725 n个点排列,给每个点着色,求其中至少有m个红色的点连续的数 ...
- ZOJ-3725 Painting Storages 动态规划
题意:给定一个数N,表示有N个位置,要么放置0,要么放置1,问至少存在一个连续的M个1的放置方式有多少? 分析:正面求解可能还要考虑到重复计算带来的影响,该题适应反面求解.设dp[i][j]表示到前 ...
- 130804组队练习赛ZOJ校赛
A.Ribbon Gymnastics 题目要求四个点作圆,且圆与圆之间不能相交的半径之和的最大值.我当时想法很简单,只要两圆相切,它们的半径之和一定最大,但是要保证不能相交的话就只能取两两个点间距离 ...
- zoj 1610 Count the Colors
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=610 Count the Colors Time Limit:2000MS ...
随机推荐
- web页面全角&半角
根据Unicode编码,全角空格为12288,半角空格为32 : 其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248 全角-->半角函数 //半角转换 ...
- ABP 仓储VIEW实现
每个view实体加个ID 对应实体属性配置到View的列 View添加一列类似自增序列 ROW_NUMBER() OVER(ORDER BY getdate()) AS ID codefirst时 删 ...
- 使用 Date 和 SimpleDateFormat 类表示时间、Calendar类和Math类
一. Date 和 SimpleDateFormat类表示时间 在程序开发中,经常需要处理日期和时间的相关数据,此时我们可以使用 java.util 包中的 Date 类.这个类最主要的作用就是获取当 ...
- WCF通过SVCUtil.exe生成客户端代理类和配置文件(转)
WCF服务调用通过两种常用的方式: 1:一种是借助代码生成工具SvcUtil.exe或者添加服务引用的方式. 2:一种是通过ChannelFactory直接创建服务代理对象进行服务调用. 本文只针对通 ...
- Nginx-->基础-->理论-->nginx进程模型
一.nginx的进程模型基础 如上图,是nginx的基本进程模型. 1.nginx的master进程与worker进程关系 nginx的master进程负责worker进程的管理,包括创建worker ...
- Create side-by-side stereo pairs in the Unity game engine
Create side-by-side stereo pairs in the Unity game engine Paul BourkeDecember 2008 Sample Island pro ...
- 磊科NI360路由器绕过密码登录
先分析正确登陆360路由器后cookies是怎么样的,发现只有一个值如下图: 可以看出登陆后只有一个netcore_login=guest:1 下面来模拟一下这个cookies看是否能登陆 增加好后直 ...
- Trie 最长前缀匹配串的实现
http://blog.csdn.net/hguisu/article/details/8131559
- 如何让电脑公司Win7系统自动关闭停止响应的程序
在注册表编辑器窗口左侧,依次展开HKEY_CURRENT_USER\ControlPanel\Desktop,选中Desktop,在右边的窗口中选择AutoEndTasks,双击打开AutoEndTa ...
- 默认构造方法并非总是public的
以前印象中一直有一个概念,说"如果没有提供构造方法,java将自动添加一个空的public的构造方法".现在看来,有2个问题,一,默认构造方法未必是public的,二,默认构造方法 ...