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 ...
随机推荐
- 图片缩放应用(nearest / bilinear / three-order interpolate)
typedef xPixel PIXELCOLORRGB; double Sinxx(double value){ if (value < 0) value = -value; if (valu ...
- mouseChildren启示
将aSprite的 mouseChildren 属性设置为 false ,可以实现mouseClick 事件的目标为 aSprite对象,而不是其子对象中的任一个.
- asp.net 页面如何将Eval中的时间显示为“yyyy-MM-dd ” 格式
<table> <tr> <td style="width:273px;color:#105db5;" valign="top&quo ...
- Vue2.0 + Element-UI + WebAPI实践:简易个人记账系统
最近正在学习Vue2.0相关知识,正好近期饿了么桌面端组件Element-UI发布,便动手做了一款简易个人记账系统,以达到实践及巩固目的. 1.开发环境 Win10 + VS2015 + Sqlser ...
- MySQL binlog基本操作
常用操作: 1. 设置启用binlog log-bin = binlog 2. 设置全备和增量备份 #crontab -e * 0 * * 7 /usr/bin/mysqldump mybinlog ...
- jfreechart 整合sturts2牛刀小试
一.增加的jar包 struts2-jfreechart-plugin-2.1.6.jar 在struts2的相应jar包中找 jcommon-1.0.23.jar ...
- 第二章 Mybatis代码生成工具
1.mybatis-generator作用 1).生成pojo 与 数据库结构对应 2).如果有主键,能匹配主键 3).如果没有主键,可以用其他字段去匹配 4).动态select,update,del ...
- IP地址子网掩码主机地址网络号主机号
(1)子网掩码1所对应的位为网络号位 而所对应的位为主机号位 IP地址+子网掩码=网络号: IP地址+子网掩码(反码)=主机号. (2)主机号中的m位被用来表示网络号了,也就是子网号,将0-255划分 ...
- WebView加载HTML图片大小自适应与文章自动换行
http://www.brighttj.com/ios/ios-webview-load-html-image-adaptive.html 在很多App中都会使用到webview,尤其是在加载新闻内容 ...
- Hadoop入门之安装配置(hadoop-0.20.2)
Hadoop,简单理解为HDFS(分布式存储)+Mapreduce(分布式处理),专为离线和大规模数据分析而设计. Hadoop可以把很多linux的廉价PC组成分布式结点,然后编程人员也不需要知道分 ...