Codeforces 659G Fence Divercity dp
我们设a[ i ] 为第 i 个围栏被切的最靠下的位置, 我们发现a[ i ] 的最大取值有一下信息:
如果从i - 1过来并在 i 结束a[ i ] = min(h[ i - 1], h[ i ])
如果从i - 1过来并延续到i + 1, a[ i ] = min(h[ i - 1 ], h[ i ], h[ i + 1 ])
如果从 i 开始 i 结束 a[ i ] = h[ i ]
如果从 i 开始并延续到 i + 1, a[ i ] = min(h[ i ], h[ i + 1])
然后我们就能dp啦, dp[ i ][ 0 ]表示到 i 结束的方案数, dp[ i ][ 1 ]表示到 i 并且要延续下去的方案数。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 1e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n;
LL h[N], dp[N][]; int main() {
scanf("%d", &n);
for(int i = ; i <= n; i++) scanf("%lld", &h[i]), h[i]--;
h[n + ] = inf;
dp[][] = h[];
dp[][] = min(h[], h[]);
LL ans = dp[][];
for(int i = ; i <= n; i++) {
dp[i][] = (dp[i - ][] * min(h[i - ], h[i]) + h[i]) % mod;
dp[i][] = ((dp[i - ][] * min(h[i - ], min(h[i], h[i + ])) % mod) + min(h[i], h[i + ])) % mod;
ans = (ans + dp[i][]) % mod;
}
printf("%lld\n", ans);
return ;
} /*
*/
Codeforces 659G 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 1201D]Treasure Hunting(DP)
[Codeforces 1201D]Treasure Hunting(DP) 题面 有一个n*m的方格,方格上有k个宝藏,一个人从(1,1)出发,可以向左或者向右走,但不能向下走.给出q个列,在这些列 ...
- codeforces 448CPainting Fence
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/y990041769/article/details/37935237 题目:codeforces 4 ...
- codeforces 659 G. Fence Divercity 组合数学 dp
http://codeforces.com/problemset/problem/659/G 思路: f(i,0/1,0/1) 表示到了第i个,要被切的块开始了没有,结束了没有的状态的方案数 递推看代 ...
- codeforces Hill Number 数位dp
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits: 5000 MS Memory Limits: ...
- codeforces B.Fence 解题报告
题目链接:http://codeforces.com/problemset/problem/363/B 题目意思:给定整数n和k,需要从n个数中找出连续的k个数之和最小,输出这连续的k个数中的第一个数 ...
- codeforces Educational Codeforces Round 16-E(DP)
题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
随机推荐
- delimiter 与 存储过程
1.如此执行语句不行,需要在 delimiter IF not EXISTS ( SELECT * FROM information_schema. COLUMNS WHERE table_schem ...
- C++中string跨DLL失败解决途径
1.问题描述: 在一个MFC应用程序exe中,调用另一个DLL中的函数,函数中的一个形参是string类型的,每次调用都会出现乱码的情况. 调用前: 调用后: 2.原因分析: 不同的模块各自有一份C运 ...
- mysql数据库导出excel xml等格式文件
http://jingyan.baidu.com/article/ac6a9a5e43a62e2b653eac83.html
- centos6安装python3.6.4
安装Python依赖包: [root@Python src]# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlit ...
- System.Runtime.InteropServices.COMException (0x800A03EC): 无法访问文件
使用Microsoft.Office.Interop.Excel 操作 今天在服务器部署,操作程序csv文件转xsl文件的时候,遇到一下问题: System.Runtime.InteropServic ...
- 量化投资与Python之NumPy
数组计算 NumPy是高性能科学计算和数据分析的基础包.它是pandas等其他各种工具的基础.NumPy的主要功能:ndarray,一个多维数组结构,高效且节省空间无需循环对整组数据进行快速运算的 ...
- pom.xml的第一行报错
第一行:<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.or ...
- elasticsearch5.0集群大数据量迁移方法及注意事项
当es集群的数据量较小的情况下elasticdump这个工具比较方便,但是当数据量达到一定级别比如上百G的时候,elasticdump速度就很慢了,此时我们可以使用快照的方法进行备份 elasticd ...
- http响应头设置
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletExcep ...
- Python-bootstrap
1 引入 如果想要用到BootStrap提供的js插件,那么还需要引入jQuery框架,因为BootStrap提供的js插件是依赖于jQuery的 <link type="text/c ...