hdu How to Type
感觉这道dp题还是有点技巧的,此题设置了两个数组:open[]和close[],分别用来记录capslock一直开启状态和一直关闭状态下的最少输入次数。此时只要判断字母的大小写,选用最优子结构即可。状态转移方程为:
str[i]是小写字母:
open[i]=min(open[i-1]+2,close[i-1]+2);
close[i]=min(close[i-1]+1,open[i-1]+2);
str[i]是大写字母:
open[i]=min(open[i-1]+1,close[i-1]+2);
close[i]=min(close[i-1]+2,open[i-1]+2);
#include"iostream"
#include"stdio.h"
#include"string.h"
#include"ctype.h"
#define mx 1000
using namespace std;
char str[mx];
int open[mx],close[mx];
int min(int a,int b)
{
return a<b?a:b;
}
int main()
{
int i,j,t;
cin>>t;
getchar();
while(t--)
{
memset(open,,sizeof(open));
memset(close,,sizeof(close));
cin>>str;
if(islower(str[])) {open[]=;close[]=;}
else {open[]=;close[]=;}
for(i=;str[i]!='\0';i++)
{
if(islower(str[i]))
{
open[i]=min(open[i-]+,close[i-]+);
close[i]=min(close[i-]+,open[i-]+);
}
else
{
open[i]=min(open[i-]+,close[i-]+);
close[i]=min(close[i-]+,open[i-]+);
}
}
cout<<close[i-]<<endl;
}
return ;
}
hdu How to Type的更多相关文章
- HDU 2577---How to Type
HDU 2577 Description Pirates have finished developing the typing software. He called Cathy to test ...
- HDU 3586 二分答案+树形DP判定
HDU 3586 『Link』HDU 3586 『Type』二分答案+树形DP判定 ✡Problem: 给定n个敌方据点,1为司令部,其他点各有一条边相连构成一棵树,每条边都有一个权值cost表示破坏 ...
- HDU 2577 How to Type (线性dp)
How to Type Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 2577 How to Type(dp题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2577 解题报告:有一个长度在100以内的字符串,并且这个字符串只有大写和小写字母组成,现在要把这些字符 ...
- hdu 2577 How to Type(dp)
Problem Description Pirates have finished developing the typing software. He called Cathy to test hi ...
- HDU 2577 How to Type (字符串处理)
题目链接 Problem Description Pirates have finished developing the typing software. He called Cathy to te ...
- HDU 2577 How to Type (字符串处理)
题目链接 Problem Description Pirates have finished developing the typing software. He called Cathy to te ...
- HDU 2577 How to Type DP也可以模拟
http://acm.hdu.edu.cn/showproblem.php?pid=2577 大意: 大家都打过字吧,现在有个有趣的问题:给你一串字符串,有大写有小写,要求你按键次数最少来输出它,输出 ...
- hdu 2577 How to Type(DP)
How to Type Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
随机推荐
- 理解和解决MySQL乱码问题
本文将详细介绍MySQL乱码的成因和具体的解决方案 在阅读本文之前,强烈建议对字符集编码概念还比较模糊的同学 阅读下博主之前对相关概念的一篇科普:十分钟搞清字符集和字符编码 MySQL出现乱码的原因 ...
- codeforces 476B.Dreamoon and WiFi 解题报告
题目链接:http://codeforces.com/problemset/problem/476/B 题目意思:给出两个字符串str1, str2,其中,str1 只由 '+' 和 '-' 组成,而 ...
- Java数据类型中String、Integer、int相互间的转换
1.Integer转换成int的方法 Integer i; int k = i.intValue(); 即Integer.intValue(); 2.int转换成Integer int i; Int ...
- 神经网络(luogu 1038 答案错误,出题人语体教)
题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神经网络的研究一直是当今 ...
- svn 创建
1.ps aux | grep svn 杀掉进程 2.svnadmin create /svnrepertory/SVNwangping 创建svn仓库; 3.修改3个文件 4.svnserve -d ...
- Solr常用查询语法笔记
1.常用查询 q - 查询字符串,这个是必须的.如果查询所有*:* ,根据指定字段查询(Name:张三 AND Address:北京) fq - (filter query)过虑查询,作用:在q查询符 ...
- watchdog机制
转自:http://blog.sina.com.cn/s/blog_4dff871201012yzh.html 什么是Watchdog? Watchdog,又称watchdog timer,是计算机可 ...
- php 的函数参数值类型限定
如例: function test(array $a,test $b){ /*...*/ } class test{ /*...*/ } test(array(),new test); 表示test函 ...
- Python读写文件乱码问题
对开发者来说,最恼人的问题之一莫过于读写文件的时候,由于编码千差万别,出现乱码问题.好难快速解决啊... 最近我也遇到了这样的问题,经研究,把大致的解决思路拿出来共享. 1. python中习惯首先声 ...
- poj 2635 千进制
转自:http://www.cnblogs.com/kuangbin/archive/2012/04/01/2429463.html 大致题意: 给定一个大数K,K是两个大素数的乘积的值. 再给定一个 ...