hdu4105 Electric wave
Electric wave
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 596 Accepted Submission(s): 173
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.
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.
712495
The separated data may have leading zeros.
#include <stdio.h>
#include <iostream>
#include <string.h>
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<j)
{
i++;
}
while(str[a]=='0'&&a<b)
{
a++;
}
int len1=j-i,len2=b-a;
if(len1<len2)
{
return 0;
}
else if(len1>len2)
{
return 1;
}
else
{
for(c=0;c<=len1;c++)
{
if(str[i+c]!=str[a+c])
{
if(str[i+c]<str[a+c])
{
return 0;
}
else
{
return 1;
}
}
}
return -1;
}
}
int fmax(int a,int b)
{
if(a>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<n;j++)
{
for(flag=0;flag<2;flag++)
for(k=j+1;k<n;k++)
{
if((flag^1)==compare(i,j,j+1,k))
dp[flag][i][j]=fmax(dp[flag][i][j],1+dp[flag^1][j+1][k]);
} }
}
} int maxx=dp[1][0][0];
for(i=0;i<n;i++)
{
if(dp[1][0][i]>maxx)
{
maxx=dp[1][0][i];
}
}
printf("%d\n",maxx);
}
return 0;
}
hdu4105 Electric wave的更多相关文章
- 简单dp hdu-4105-Electric wave
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4105 题目意思: 给一个字符串,求最大的分隔空格数,记所有被分隔的数为a1,a2,a3,..... ...
- RIFF和WAVE音频文件格式
RIFF file format RIFF全称为资源互换文件格式(Resources Interchange File Format),是Windows下大部分多媒体文件遵循的一种文件结构.RIFF文 ...
- IEEE 802.11p (WAVE,Wireless Access in the Vehicular Environment)
IEEE 802.11p(又称WAVE,Wireless Access in the Vehicular Environment)是一个由IEEE 802.11标准扩充的通讯协定.这个通讯协定主要用在 ...
- Wave - 花たん 音乐
Wave 歌手:花たん 所属专辑:Flower 間違えて宇宙終わって(宇宙因为一个错误而终结了) 青信号はいつも通り(通行的灯号一如往常的) 飛んでまた止まって(又再停止传播) また 飛びそうだ(然后 ...
- Web 播放声音(AMR 、WAVE)
最近甚是苦闷,属于边学边做,跳进了很多坑,别提有多惨了,不过结果还是不错滴,纵观前后,一句话足以概括 “痛并快乐着” ~~~ ok,我少说废话,下面来总结下 Web 播放声音一些注意事项. 说到 We ...
- 多媒体(2):WAVE文件格式分析
目录 多媒体(1):MCI接口编程 多媒体(2):WAVE文件格式分析 多媒体(3):基于WindowsAPI的视频捕捉卡操作 多媒体(4):JPEG图像压缩编码 多媒体(2):WAVE文件格式分析
- UVa 488 - Triangle Wave
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=s ...
- modelsim 中 WAVE窗口中能不能只显示变量名,而不显示路径
可以的,在wave窗口左下角有一个黑色的logo,你点击它就可以省电路径,只显示port名称,再点击就切换回来了,如图红色圈圈标记的logo,你可以试试!
- C# 获取wave文件信息【转】
public class WaveHelper { /// <summary> /// 数据流 /// </summary> private Stream m_WaveData ...
随机推荐
- HDU 472 Hamming Distance (随机数)
Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) To ...
- perl学习(9) 实例:取出操作时间最长的100个记录
需求描述: 日志记录了一次操作的时间,即server端接收包到发送结果到client端的时间,取出操作时间最长的100个记录. 日志信息片段: [2013-09-13 15:23:50,445.500 ...
- Javascript 中的非空判断 undefined,null, NaN的区别
JS 数据类型 在介绍这三个之间的差别之前, 先来看一下JS 的数据类型. 在 Java ,C这样的语言中, 使用一个变量之前,需要先定义这个变量并指定它的数据类型,是整型,字符串型,.... 但是 ...
- linux脚本: makefile以及链接库
Linux makefile 教程 非常详细,且易懂 http://blog.csdn.net/liang13664759/article/details/1771246 //sort.c #incl ...
- linux+Qt程序如何打包发布
源地址:http://zhidao.baidu.com/link?url=UTWEoXS21B4p1L5LJmYgGBMAr0dTdXfzmaGbWeltnwQLA3Uc9_K9RcDQFFIArbx ...
- Delphi - SEH研究
技术交流,DH讲解. 前几天一个朋友在弄游戏外挂想带NP调试,就像自己来捕获游戏的异常.好像就要用到SEH这方面的知识.一起研究了一下,这里看下研究 和 在网上找的资料吧.SEH就是Structure ...
- python中文注释及输出出错
今天开始接触python,中文报错,你懂的,不细说. 网上很多类似的解决方案,有不是很明确,例如:http://blog.csdn.net/chen861201/article/details/770 ...
- Android 事件处理
目的:通过全面的分析Android的鼠标和键盘事件.了解Android中如何接收和处理键盘和鼠标事件,以及如何用代码来产生事件. 主要学习内容: 1. 接收并处理鼠标事件:按下.弹起.移动.双击.长按 ...
- 慎得慌二u赫然共和任务i个屁
http://www.huihui.cn/share/8424421 http://www.huihui.cn/share/8424375 http://www.huihui.cn/share/842 ...
- VK Cup 2012 Qualification Round 1---C. Cd and pwd commands
Cd and pwd commands time limit per test 3 seconds memory limit per test 256 megabytes input standard ...