http://codeforces.com/problemset/problem/659/G

思路:

f(i,0/1,0/1) 表示到了第i个,要被切的块开始了没有,结束了没有的状态的方案数

递推看代码:

  //File Name: cf659G.cpp//Created Time: 2016年07月12日 星期二 12时40分28秒

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream> #define LL long long using namespace std; const int MAXN = + ;
const int MOD = (int)1e9 + ; LL h[MAXN];
LL f[MAXN][][]; LL solve(int n){
h[n+] = ;
memset(f,,sizeof f);
f[][][] = ;
for(int i=;i<=n;i++){
f[i][][] = ;
(f[i][][] = f[i-][][] + h[i] - + f[i-][][] * min(h[i]-,h[i-]-) % MOD) %= MOD;
(f[i][][] = min(h[i],h[i+]) - + f[i-][][] * min(min(h[i-]-,h[i]-),h[i+]-)) %= MOD;
//printf("i = %d %lld %lld\n",i,f[i][1][0],f[i][1][1]);
}
return f[n][][];
} int main(){
int n;
while(~scanf("%d",&n)){
for(int i=;i<=n;i++)
scanf("%d",&h[i]);
printf("%d\n",(int)solve(n));
}
return ;
}

codeforces 659 G. Fence Divercity 组合数学 dp的更多相关文章

  1. codeforces 659G G. Fence Divercity(dp)

    题目链接: G. Fence Divercity time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. Codeforces Round #346 (Div. 2) G. Fence Divercity dp

    G. Fence Divercity 题目连接: http://www.codeforces.com/contest/659/problem/G Description Long ago, Vasil ...

  3. codeforces Make The Fence Great Again(dp)

    题目链接:http://codeforces.com/contest/1221/problem/D 题目要求ai ! = ai-1,草纸上推理一下可以发现每一个栅栏可以升高的高度无非就是 +0,+1, ...

  4. Codeforces 659G Fence Divercity dp

    Fence Divercity 我们设a[ i ] 为第 i 个围栏被切的最靠下的位置, 我们发现a[ i ] 的最大取值有一下信息: 如果从i - 1过来并在 i  结束a[ i ] = min(h ...

  5. Codeforces 461B Appleman and Tree(木dp)

    题目链接:Codeforces 461B Appleman and Tree 题目大意:一棵树,以0节点为根节点,给定每一个节点的父亲节点,以及每一个点的颜色(0表示白色,1表示黑色),切断这棵树的k ...

  6. [CodeForces - 1225E]Rock Is Push 【dp】【前缀和】

    [CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory ...

  7. [codeforces 549]G. Happy Line

    [codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love ...

  8. CodeForces 794 G.Replace All

    CodeForces 794 G.Replace All 解题思路 首先如果字符串 \(A, B\) 没有匹配,那么二元组 \((S, T)\) 合法的一个必要条件是存在正整数对 \((x,y)\), ...

  9. 【uoj#22】[UR #1]外星人 组合数学+dp

    题目描述 给你一个长度为 $n$ 的序列 $\{a_i\}$ 和一个数 $x$ ,对于任意一个 $1\sim n$ 的排列 $\{p_i\}$ ,从 $1$ 到 $n$ 依次执行 $x=x\ \tex ...

随机推荐

  1. 分布式系统开发的一些相关理论基础——CAP、ACID、BASE

    本文主要讲述分布式系统开发的一些相关理论基础. 一.ACID 事务的四个特征: 1.Atomic原子性 事务必须是一个原子的操作序列单元,事务中包含的各项操作在一次执行过程中,要么全部执行成功,要么全 ...

  2. iOS开发UI篇—iPad开发中得modal介绍

    iOS开发UI篇—iPad开发中得modal介绍 一.简单介绍 说明1: 在iPhone开发中,Modal是一种常见的切换控制器的方式 默认是从屏幕底部往上弹出,直到完全盖住后面的内容为止 说明2: ...

  3. [转载]javaEE规范和SSH三大框架到底有什么关系

    转载自: http://blog.csdn.net/bingjing12345/article/details/20641891 1994-2000 年是互联网的大航海时代. 请注意,下面的时间点及其 ...

  4. 【lattice软核】MICO8流程

    The LatticeMico System software is composed of three bundled applications:  Mico System Builder (MS ...

  5. 转: jdbc连接数据库需要注意和出错的地方

    * 1.数据库登录模式不能只使用windows登录模式,要采取混合模式登录, * 并记住相应的密码和账户: * 2.连接数据库后一定要记得关闭资源,否则就会造成资源浪费. * 关闭的时候也要注意顺序, ...

  6. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  7. SSH框架构建微信公众帐号服务器小技巧

    SSH框架构建微信公众帐号服务器小技巧 熟悉struts2和servlet的同学应该清楚,struts2的方法多样性弥补了servlet单一的doGet 和doPost方法.如果自己的公众账号服务器是 ...

  8. realestate.cei.gov.cn

    using AnfleCrawler.Common; using System; using System.Collections.Concurrent; using System.Collectio ...

  9. iOS系统消息

    一.键盘1.UIKeyboardWillShowNotification-将要弹出键盘2.UIKeyboardDidShowNotification-显示键盘3.UIKeyboardWillHideN ...

  10. sqoop的export的说明

    1.通用参数说明