博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu4105  Electric wave
阅读量:5240 次
发布时间:2019-06-14

本文共 2183 字,大约阅读时间需要 7 分钟。

Electric wave

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 596 Accepted Submission(s): 173

Problem Description
Ali was doing a physic experiment which requires him to observe an electric wave. He needs the height of each peak value and valley value for further study (a peak value means the value is strictly larger than its neighbors and a valley value means the value is strictly smaller than its neighbors). He did write these numbers down but he was too careless that he wrote them in a line without separations, such as “712495” may represent “7 12 4 9 5”. The only information he can remember was:
1. The data begins with a valley value
2. Each value is either a peak value or a valley value
Now he wants to insert blanks to make the data valid. If multiple solutions exist, he will choose the one with more blanks.
 

 

Input
The input consists several testcases.
The first line contains one integer N (1 <= N <= 100), the length of the data.
The second line contains one string S, the data he recorded.
S contains only digits.
 

 

Output
Print one integer, the maximum number of blanks he can insert.
 

 

Sample Input
6 712495
 

 

Sample Output
4
Hint
The separated data may have leading zeros.
 

 

Source
就是把一个字符串分成一个个小串,保证是一大一小,我们用dp[flag][i][j]表示第一位是谷还是峰,第一位是从i到j这一段,dp[flag][i][j]=fmax(dp[flag^1][j+1][k]),这样复杂度为n^3,不过,也没有什么好的优化方法,反正a这一题没有问题吧!
#include 
#include
#include
using namespace std;char str[105];int dp[2][105][105];int compare(int i,int j,int a,int b )//前面小返回0大返回1{ int c; while(str[i]=='0'&&i
len2) { return 1; } else { for(c=0;c<=len1;c++) { if(str[i+c]!=str[a+c]) { if(str[i+c]
b) return a; return b;}int main (){ int n,flag,i,j,k; while(scanf("%d",&n)!=EOF) { scanf("%s",str); memset(dp,0,sizeof(dp)); { for(i=n-1;i>=0;i--) { for(j=i;j
maxx) { maxx=dp[1][0][i]; } } printf("%d\n",maxx); } return 0;}
 

 

转载于:https://www.cnblogs.com/jiangu66/p/3243870.html

你可能感兴趣的文章
比较安全的获取站点更目录
查看>>
苹果开发者账号那些事儿(二)
查看>>
使用C#交互快速生成代码!
查看>>
UVA11374 Airport Express
查看>>
P1373 小a和uim之大逃离 四维dp,维护差值
查看>>
NOIP2015 运输计划 树上差分+树剖
查看>>
P3950 部落冲突 树链剖分
查看>>
读书_2019年
查看>>
读书汇总贴
查看>>
微信小程序 movable-view组件应用:可拖动悬浮框_返回首页
查看>>
MPT树详解
查看>>
空间分析开源库GEOS
查看>>
RQNOJ八月赛
查看>>
前端各种mate积累
查看>>
jQuery 1.7 发布了
查看>>
Python(软件目录结构规范)
查看>>
Windows多线程入门のCreateThread与_beginthreadex本质区别(转)
查看>>
Nginx配置文件(nginx.conf)配置详解1
查看>>
linux php编译安装
查看>>
name phone email正则表达式
查看>>