UVALive 7276 Wooden Signs (DP)
Wooden Signs
题目链接:
http://acm.hust.edu.cn/vjudge/contest/127406#problem/E
Description
http://7xjob4.com1.z0.glb.clouddn.com/0f10204481da21e62f8c145939e5828e
Input
The input file contains several test cases, each of them as described below.
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.
Constraints:
1 ≤ N
Output
For each test case, the output has a single line with the number (modulo 2
31 − 1 = 2147483647) of
distinct signs that can be described by the given permutation.
Sample Input
5
2 6 5 1 4 3
2
2 3 1
20
3 21 10 15 6 9 2 5 20 13 17 19 14 7 11 18 16 12 1 8 4
Sample Output
6
1
1887
##题意:
木匠要做N个路标并把它们钉在一起(如图).
每个路标可以朝左也可以朝右,但是每个路标的起点要跟下一层路标的起点或终点重合. 重合位置必须有面积覆盖,不能像231右图那种只重合一个点.
现在他不记得这些路标各自的朝向了. 但是他记得N+1个值,其中第i个值是第i个路标的起点坐标. (第N+1为最后一块的终点).
求可能满足条件的路标有多少种情况. (区别在于各自的朝向)(第一块路标一定朝右)
##题解:
考虑每块路标的终点:
若第i块路标的坐标区间为[L, R], 第i+1块路标的终点为Xi+1.
那么基于第i块路标来摆放第i+1块的方式有两种:
①第i+1块的起点在L处(朝右). 这要求 Xi+1 > L .
②第i+1块的起点在R处(朝左). 这要求 Xi+1
##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 2016
#define mod 2147483647LL
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
using namespace std;
LL dp[maxn][2][maxn];
int n, arrow[maxn];
int main(int argc, char const *argv[])
{
//IN;
while(scanf("%d", &n) != EOF)
{
int leftmost; scanf("%d", &leftmost);
for(int i=1; i<=n; i++)
scanf("%d", &arrow[i]);
memset(dp, 0, sizeof(dp));
dp[1][0][leftmost] = 1;
for(int i=1; i<n; i++) {
for(int j=1; j<=n+1; j++) {
if(dp[i][0][j]) {
if(arrow[i+1] > j) dp[i+1][0][j] = (dp[i+1][0][j] + dp[i][0][j]) % mod;
if(arrow[i+1] < arrow[i]) dp[i+1][1][arrow[i]] = (dp[i+1][1][arrow[i]] + dp[i][0][j]) % mod;
}
if(dp[i][1][j]) {
if(arrow[i+1] < j) dp[i+1][1][j] = (dp[i+1][1][j] + dp[i][1][j]) % mod;
if(arrow[i+1] > arrow[i]) dp[i+1][0][arrow[i]] = (dp[i+1][0][arrow[i]] + dp[i][1][j]) % mod;
}
}
}
LL ans = 0;
for(int j=1; j<=n+1; j++) {
ans = (ans + dp[n][0][j]) % mod;
ans = (ans + dp[n][1][j]) % mod;
}
printf("%lld\n", ans);
}
return 0;
}
UVALive 7276 Wooden Signs (DP)的更多相关文章
- UVALive 7276 Wooden Signs
详细题目见:http://7xjob4.com1.z0.glb.clouddn.com/0f10204481da21e62f8c145939e5828e 思路:记dp[i][j]表示第i个木板尾部在j ...
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
- UVA11125 - Arrange Some Marbles(dp)
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- 初探动态规划(DP)
学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...
- Tour(dp)
Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...
- 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)
.navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...
- Leetcode之动态规划(DP)专题-详解983. 最低票价(Minimum Cost For Tickets)
Leetcode之动态规划(DP)专题-983. 最低票价(Minimum Cost For Tickets) 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行.在接下来的一年里,你要旅行的 ...
随机推荐
- CentOS 6.5系统使用yum方式安装LAMP环境和phpMyAdmin详细过程
介绍如何在CentOs6.2下面使用YUM配置安装LAMP环境,一些兄弟也很喜欢使用编译的安装方法,个人觉得如果不是对服务器做定制,用yum安装稳定简单,何必去download&make&am ...
- Effective C++学习笔记 条款06:如不想使用编译器自动生成的函数,就该明确拒绝
一.为驳回编译器自动提供的机能,可将相应成员函数声明为private并且不予实现.(如果你仅仅是自己不实现的话,编译器会帮你实现) 如: class A { public: A(const strin ...
- poj 1905 Expanding Rods (数学 计算方法 二分)
题目链接 题意:将长度为L的棒子卡在墙壁之间.现在因为某种原因,木棒变长了,因为还在墙壁之间,所以弯成了一个弧度,现在求的是弧的最高处与木棒原先的地方的最大距离. 分析: 下面的分析是网上别人的分析: ...
- BZOJ_1628_[Usaco2007_Demo]_City_skyline_(单调栈)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1628 给出\(n\)个距形的影子,问最少是多少个建筑的?(建筑的影子可以重叠). 分析 用单调 ...
- Android 怎样使用API
本文针对Android开发如何使用API文档进行一些经验分享. 1.为什么需要掌握API的使用. 也许你需要完成一个功能时很多时候你在网上google一番,因为很可能找到有用的代码片段,甚至不用关心具 ...
- codeforces 334B - Eight Point Sets
题意难懂,其实就是x1<x2<x3与y1<y2<y3两两组合成九个点,去掉(x2,y2),剩余八个.这样的八个点才是满足要求的. 忘去重了 #include<cstdio ...
- MySQL操作备忘录
在mysql包中,mysqld是数据库服务器,mysql是客户端,mysqladmin则用于管理数据库服务器的信息,如用户密码等. 关于安装: 1.在d:/sftwr/mysql/bin目录下: my ...
- ORACLE 如何定位消耗资源的SQL
在分析SQL性能的时候,经常需要确定资源消耗多的SQL,总结如下: 1 查看值得怀疑的SQLselect substr(to_char(s.pct, '99.00'), 2) || '%' load, ...
- db2数据库Date相关函数
1.db2可以通过SYSIBM.SYSDUMMY1.SYSIBM.DUAL获取寄存器中的值,也可以通过VALUES关键字获取寄存器中的值. SELECT 'HELLO DB2' FROM SYSIBM ...
- MSSQL 2005数据库与SP4补丁安装
Sql Server 2005 正确安装之前的win7配置: http://wenku.baidu.com/link?url=6T3jzVnu2XY_sfqfe9ZqQ_6dUOdrZwHc83baW ...