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 ...
随机推荐
- JDE Client开发端 左侧边栏设置
- CXF支持 SOAP1.1 SOAP1.2协议
SOAP协议分为两个版本 1.1 1.2 默认支持1.1 实现方式: 1.编写接口 import javax.jws.WebService; @WebService public inte ...
- QB资料学习.01
1.多数据集的读取 A.取数SQL的配置,借用TStringList进行存储多个不同的取数SQL B.DBA取数: DBA.ReadMultipleDataSet(TStringList) C.结果 ...
- hdoj 4323
题意:给你n个数,m个查询,查询中包括一个数和一个最大编辑距离d,问n个数中和这个数的编辑距离不超过d的有多少个 编辑距离:http://baike.baidu.com/view/2020247.ht ...
- 生成XML文件
import java.io.FileOutputStream;import java.io.IOException; import org.jdom.Document;import org.jdom ...
- ubuntu fix the grub boot(need Internet)
sudo add-apt-repository ppa:yannubuntu/boot-repair sudo apt-get update sudo apt-get install -y boot- ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)
A.暴力枚举,注意游戏最长为90分钟 B.暴力,c[l]++,c[r]--,记录中间有多长的段是大小为n的,注意特判m=0的情况 C.暴力枚举,我居然一开始没想出来!我一直以为每次都要统计最大的,就要 ...
- Brief Tour of the Standard Library
10.1. Operating System Interface The os module provides dozens of functions for interacting with the ...
- Asp.Net异步导入Excel
故事:用户在页面上传一个excel文件,程序把excel里的内容入库. 技术方案:保存文件在服务器,jquey Ajax 异步读取文件中的记录到数据库,在页面实时刷新导入情况 页面前端 <%@ ...
- RBL开发笔记二
17:13:55 2014-08-25 有以下几个点: 第一 :怎么在预处理阶段能够做到识别某个宏是否给定义了 这里就定义了一个SystemConfig.h 专门做这个事情 当然是需要make ...