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 ...
随机推荐
- 【堆栈应用一】一个数divided=几个最小质因数的乘积(时间复杂度On)
此算法由LQD提供
- JavaScript常见问题整合
一. 基本变化<SCRIPT LANGUAGE="javascript"> <!-- window.open ('page.html', 'newwindow', ...
- 通过MD5排除重复文件
今天下载了好多美女图片壁纸,可是看了一下发现好多图片重复了,有强迫症的我必须把重复的都给剔除掉,首先想到的当然是百度了,问问度娘有没有什么图片去重的工具,搜了一下还真有.奈何本人智商捉急用不来这高级的 ...
- 用maven搭建 testNG+PowerMock+Mockito测试框架
单元测试是开发中必不可少的一部分,是产品代码的重要保证. Junit和testNG是当前最流行的测试框架,Junit是使用最广泛的测试框架,有兴趣的话自己baidu一下. testNG基于Junit和 ...
- [UML][转]UML类图符号 各种关系说明以及举例
修改自:http://www.cnblogs.com/duanxz/archive/2012/06/13/2547801.html UML中描述类和类之间相互关系的方式包括:依赖(Dependency ...
- C# 6.0新特性(转载)
简介 VS 2015中已经包含C# 6.0. C#在发布不同版本时,C#总是会有新特性,比如C#3.0中出现LINQ,C#4.0中的动态特性,c#5.0中的异步操作等.. C# 6.0中与增加了不少新 ...
- MySQL主机127.0.0.1与localhost区别总结
1. mysql -h 127.0.0.1 的时候,使用TCP/IP连接, mysql server 认为该连接来自于127.0.0.1或者是"localhost.localdomain&q ...
- Android Studio Tips and Tricks
Android Studio Delete Module 1.选中Module右击,选择 Open Module Settings,打开Project Structure 窗空.(或者选中Module ...
- C#—WebService
一.qq是否在线 1.添加Web引用 qqOnlineWebService cn.com.webxml.www.qqOnlineWebService shelly1 = new NIIT1109 ...
- Python UDP broadcast PermissionError: [Errno 13] Permission denied
/********************************************************************** * Python UDP broadcast Permi ...