codeforces 659 G. Fence Divercity 组合数学 dp
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的更多相关文章
- codeforces 659G G. Fence Divercity(dp)
题目链接: G. Fence Divercity time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces Round #346 (Div. 2) G. Fence Divercity dp
G. Fence Divercity 题目连接: http://www.codeforces.com/contest/659/problem/G Description Long ago, Vasil ...
- codeforces Make The Fence Great Again(dp)
题目链接:http://codeforces.com/contest/1221/problem/D 题目要求ai ! = ai-1,草纸上推理一下可以发现每一个栅栏可以升高的高度无非就是 +0,+1, ...
- Codeforces 659G Fence Divercity dp
Fence Divercity 我们设a[ i ] 为第 i 个围栏被切的最靠下的位置, 我们发现a[ i ] 的最大取值有一下信息: 如果从i - 1过来并在 i 结束a[ i ] = min(h ...
- Codeforces 461B Appleman and Tree(木dp)
题目链接:Codeforces 461B Appleman and Tree 题目大意:一棵树,以0节点为根节点,给定每一个节点的父亲节点,以及每一个点的颜色(0表示白色,1表示黑色),切断这棵树的k ...
- [CodeForces - 1225E]Rock Is Push 【dp】【前缀和】
[CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory ...
- [codeforces 549]G. Happy Line
[codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love ...
- CodeForces 794 G.Replace All
CodeForces 794 G.Replace All 解题思路 首先如果字符串 \(A, B\) 没有匹配,那么二元组 \((S, T)\) 合法的一个必要条件是存在正整数对 \((x,y)\), ...
- 【uoj#22】[UR #1]外星人 组合数学+dp
题目描述 给你一个长度为 $n$ 的序列 $\{a_i\}$ 和一个数 $x$ ,对于任意一个 $1\sim n$ 的排列 $\{p_i\}$ ,从 $1$ 到 $n$ 依次执行 $x=x\ \tex ...
随机推荐
- C#/ASP.NET MVC微信公众号接口开发之从零开发(二) 接收微信消息并且解析XML(附源码)
文章导读: C#微信公众号接口开发之从零开发(一) 接入微信公众平台 微信接入之后,微信通过我们接入的地址进行通信,其中的原理是微信用户发送消息给微信公众账号,微信服务器将消息以xml的形式发送到我们 ...
- 爱默生UPS并机系统:进入与退出操作方法
UPS并机系统的进入与退出: 进入:.合UPS的出线及进线开关:开启第一台UPS,等待整流指示灯常亮.然后Invert On,正常开机,此时UPS进入逆变状态 .合另外一台UPS的出线及进线开关,等待 ...
- numtoyminterval函数——数字转换函数
numtoyminterval函数——数字转换函数 ----转至51CTO 水滴的博客 语法:NUMTOYMINTERVAL ( n , 'char_expr' ) c ...
- Java类文件最大限制
今天在往一个jsp文件里添加代码时,项目跑起来访问这个jsp时报错.. The code of method _jspService(HttpServletRequest, HttpServletRe ...
- Android中Handler的消息处理
关于Handler机制,能找到无数的文章.http://blog.csdn.net/jiangshitian/article/details/12525313这篇博客写得比较好,关键是图很清晰,结合H ...
- java基础之 内部类
Java中的内部类共分为四种: 静态内部类static inner class (also called nested class) 成员内部类member inner class 局部内部类loca ...
- Qt之WebKit学习之绘图
void Serial::on_pushButton_clicked() { //scroll(4,0); flag_btn = true; // this->update(); //绘图绘在窗 ...
- CSS强制中英文换行与不换行
1. word-break:break-all; 只对英文起作用,以字母作为换行依据 2. word-wrap:break-word; 只对英文起作用,以单词作为换行依据 3. white-space ...
- jboss入门学习1
环境准备 win8 jdk1.6 jboss4.0.5 oracle10g 修改jboss默认端口 server/default/conf/jboss-service.xml 1.WebService ...
- fifo write
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types. ...