方向标

  • 题目信息
    • 输入
    • 输出
    • 测试样例
  • 解答

题目信息

A carpenter has received an order for a wooden directional sign. Each board must be aligned vertically with the previous one, either to the basis of the previous arrowhead or to the opposite side, being fixed there with a specially designed screw. The two boards must overlap. The carpenter wrote down a sequence of integers to encode the sketch sent by the designer but the sequence does not determine a unique model and he has thrown away the original sketch. What looked like a trivial task turned out a big jigsaw to him.

The sequence (with 1 + N elements) encodes the (N) arrows from the bottom to the top of the sign. The first element is the position of the left side of the bottom arrow. The remaining N elements define the positions where the arrowheads start, from bottom to top: the i-th element is the position where the i-th arrowhead basis is. For instance, the two signs depicted (on the left and on the right) could be encoded by 2 6 5 1 4.
Since a board must be aligned vertically with the previous one (either to the basis of the previous arrowhead or to the opposite side), if the sequence was 2 6 5 1 4 3, the fifth arrow could be fixed (in any of the depicted signs) with a screw either at 1 (pointing to the right) or at 4 (pointing to the left), with the arrowhead basis at 3.
If the sequence was 2 3 1, the second arrow could only be fixed with a screw at 3, pointing to the left, because consecutive boards must overlap.

All arrowheads are similar and the designer told the carpenter that their bases stand in different vertical lines, as well as the left side of the bottom arrow, altogether forming a permutation of 1…(N +1). That is why the carpenter overlooked the details and just wrote down the permutation (e.g., 2 6 5 1 4 3).
Given the sequence of numbers the carpenter wrote down, compute the number of directional arrows signs that can be crafted. Since the number can be very large, you must write it modulo 2147483647. The second integer in the sequence is always greater than the first one (the bottom arrow points to the right always).

输入

The first line has one integer N and the second line contains a permutation of the integers from 1 to N + 1. Integers in the same line are separated by a single space.

输出

The output has a single line with the number (modulo 2147483647) of distinct signs that can be described by the given permutation.

1 ≤ N ≤ 2000

测试样例

测试样例1

2
2 3 1
1

测试样例2

5
2 6 5 1 4 3
6

测试样例3

20
3 21 10 15 6 9 2 5 20 13 17 19 14 7 11 18 16 12 1 8 4
1887

解答

#include <iostream>
#include <vector>
#include <algorithm>#define ll long long
#define mod 2147483647using namespace std;ll dp[2005][2005];
ll head[2005];ll max(ll a, ll b)
{if (a > b)return a;elsereturn b;
}ll min(ll a, ll b)
{if (a > b)return b;elsereturn a;
}int main()
{//freopen("E://test.txt", "r", stdin);ll N;cin >> N;cin >> head[0];dp[1][head[0]] = 1;//初始化for (int i = 1; i <= N; i++){cin >> head[i];for (int j = 0; j < N + 2; j++){ll left = min(head[i - 1], j);ll right = max(head[i - 1], j);if (head[i] <= left){dp[i][right] = (dp[i - 1][j] + dp[i][right]) % mod;}if (head[i] >= right){dp[i][left] = (dp[i - 1][j] + dp[i][left]) % mod;}if (head[i] < right && head[i] > left){dp[i][left] = (dp[i - 1][j] + dp[i][left]) % mod;dp[i][right] = (dp[i - 1][j] + dp[i][right]) % mod;}}}ll ans = 0;for (int i = 0; i < N + 2; i++){ans = (ans + dp[N][i]) % mod;}cout << ans << endl;return 0;
}

方向标Directional Sign相关推荐

  1. 方向标 | c++ | 动态规划

    一.题目描述 A carpenter has received an order for a wooden directional sign. Each board must be aligned v ...

  2. [转贴]Ultimate List of Free Windows Software from Microsoft

    [原文连接]http://bhandler.spaces.live.com/blog/cns!70F64BC910C9F7F3!1231.entry Ultimate List of Free Win ...

  3. php+rsa生成签名sign,PHP 做 RSA 签名 生成订单(支付宝例子)

    /组合签名 $a=time(); $b=substr($a, 1); //生成随机订单号 $orderid= $b.mt_rand(10000,99999); //合作身份者id,以2088开头的16 ...

  4. Leetcode 764. Largest Plus Sign

    思路:动态规划.对于第i行第j列的元素grid[i][j]表示的是这个元素的plus sign的等级,初始化不在mines中的元素对应的grid值为较大值(只要大于N/2即可),在mines中的元素对 ...

  5. App开放接口api安全:Token签名sign的设计与实现

    点击上方蓝色"方志朋",选择"设为星标"回复"666"获取独家整理的学习资料! 来源:cnblogs.com/whcghost/p/5657 ...

  6. (转)Python rsa 签名与验证 sign and verify

    转自:http://wawehi.blog.163.com/blog/static/143780306201371361120515/ 网上一搜一大把的 python rsa 相关的东西,python ...

  7. ssh时出现 Agent admitted failure to sign using the key

    在将自己的公钥添加到要登陆的机器上时,仍然不能免密码登陆,并出现以下提示: Agent admitted failure to sign using the key. 需要进行以下操作即可解决: ss ...

  8. Code Sign error: Provisioning profile 'xxxxxxxxxxxxxxxxxxxxxxxxx'

    在Xcode中当你在更新了你得证书而再重新编译你的程序,真机调试一直会出现 Code Sign error: Provisioning profile 'XXXX' can't be found是不是 ...

  9. Twitter团队最新研究:快速高效的可扩展图神经网络SIGN

    今天给大家介绍的是Twitter研究团队发表的一篇论文,该研究针对大规模图神经网络训练的问题,提出的一种新的结构更加简单的模型--SIGN,这种模型的提出使得计算复杂度大大降低,能够有效地处理大规模图 ...

最新文章

  1. 下一个10年,解决问题靠“大脑”
  2. 使用pt-slave-delay实现mysql的延迟备份
  3. 探究 Java 应用的启动速度优化
  4. Java动物类enjoy方法打印,面向对象编程题汇总
  5. 大数据平台系统设计包括哪些
  6. java怎么看内存值_【java】内存分析
  7. 记录Access数据库更新操作大坑一个
  8. Assembly.CreateInstance()与Activator.CreateInstanc
  9. thinkphp5微信公众号推送模板消息
  10. python使用numpy按一定格式读取bin文件
  11. 微信能上但浏览器无法上网
  12. Leetcode惊现马化腾每天刷题?为啥大佬都这么努力!
  13. 全球建筑物提取数据集(免费下载):微软/GlobalMLBuildingFootprints
  14. php imap 安装_PHP安装IMAP扩展
  15. mplfinance 一个堪称完美python量化金融可视化工具详析
  16. Excel 使用vba脚本按条件清除行数据
  17. 可视化系列汇总——相关关系图形
  18. 运用Java制作一个属于自己的音乐播放软件
  19. 分布式数据库架构及企业实践(基于Mycat中间件)——1
  20. sp_depends 查找表的依奈项

热门文章

  1. MIPS微程序CPU设计(Logism)
  2. 【微服务架构】微服务设计模式
  3. 现代主页设计应包含的基本要素
  4. jQuery遍历之closest()方法
  5. 基于QT实现简易音视频播放器
  6. Agora 教程 | 在 Android 端实现实时视频的美颜
  7. android 获取移动网络,Android获取移动当前APP移动流量的方法
  8. Generative Adversarial Nets 论文翻译
  9. java找不到java.dll(两种情况)
  10. Windows磁盘管理(虚拟磁盘)