Fence Divercity

我们设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的更多相关文章

  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 1201D]Treasure Hunting(DP)

    [Codeforces 1201D]Treasure Hunting(DP) 题面 有一个n*m的方格,方格上有k个宝藏,一个人从(1,1)出发,可以向左或者向右走,但不能向下走.给出q个列,在这些列 ...

  4. codeforces 448CPainting Fence

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/y990041769/article/details/37935237 题目:codeforces 4 ...

  5. codeforces 659 G. Fence Divercity 组合数学 dp

    http://codeforces.com/problemset/problem/659/G 思路: f(i,0/1,0/1) 表示到了第i个,要被切的块开始了没有,结束了没有的状态的方案数 递推看代 ...

  6. codeforces Hill Number 数位dp

    http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits:  5000 MS   Memory Limits: ...

  7. codeforces B.Fence 解题报告

    题目链接:http://codeforces.com/problemset/problem/363/B 题目意思:给定整数n和k,需要从n个数中找出连续的k个数之和最小,输出这连续的k个数中的第一个数 ...

  8. codeforces Educational Codeforces Round 16-E(DP)

    题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...

  9. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

随机推荐

  1. VC++中LogFont设置字体(转)

    LOGFONT是Windows内部字体的逻辑结构,主要用于设置字体格式,其定义如下:typedef struct tagLOGFONTA{LONG lfHeight;LONG lfWidth;LONG ...

  2. Postfix 邮件服务 - PostfixAdmin

    PostfixAdmin 基于web的postfix邮件发送服务器的管理工具,可以直接管理postfix的虚拟域名和邮件用户,前提是这些数据是存储在mysql或者是PostgreSQL数据库中. Po ...

  3. JavaScript之加载表格、表单行数据[插件]

    /*** * name:加载表格或表单数据[通用] * name:load-table-or-form-data-common.js * * author:zengtai * date:2017-07 ...

  4. UVA565 Pizza Anyone? (状态压缩,搜索)

    UVA565 Pizza Anyone? 大致题意:现在你要做一份披萨,有A到P共16种食材.现在给你1~12个人对这个披萨加入不同食材的条件(只包含想要和不想要两种)(加号是想要,减号是不想要,不一 ...

  5. shell 终端常用插件

    参考链接: http://get.ftqq.com/992.get 1.zsh 2.autojump 3.apt-get install lamp-server^ 4.tldr 5.tree (显示目 ...

  6. 移动前端框架,require.js压缩

    static css images 不同的页面可以新建不同的图片文件夹(可选) js libs       前端类库 plugs    插件 views    自己写的代码文件 sass/less l ...

  7. 一个DOS攻击木马的详细分析过程

    一个DOS攻击木马的详细分析过程 0×01 起因 网路流量里发现了大量的的1.exe的文件,而且一直在持续,第一感觉就像是一个木马程序,而且每个1.exe的MD5都不一样,对比发现只有几个字节不一样( ...

  8. window系列

    1.关闭浏览器单个网页   ctrl+W 2.远程桌面连接  mstsc

  9. WebRTC架构和协议栈-zz

    为了便于理解,我们来看一个最基本的三角形WebRTC架构(图4).在这个架构中,移动电话用“浏览器M”表示,笔记本电脑用“浏览器L”表示,通过Web服务器将它们连接起来.要建立一个实时媒体通讯,两台设 ...

  10. jquery筛选数组之grep、each、inArray、map的用法及遍历son对象(转)

    grep [传入的参数为返回bool类型的函数] <script type='text/javascript' src="/jquery.js"></script ...