Problem Description
Pirates have finished developing the typing software. He called Cathy to test his typing software. She is good at thinking. After testing for several days, she finds that if she types a string by some ways, she will type the key at least. But she has a bad habit that if the caps lock is on, she must turn off it, after she finishes typing. Now she wants to know the smallest times of typing the key to finish typing a string.
 
Input
The first line is an integer t (t<=100), which is the number of test case in the input file. For each test case, there is only one string which consists of lowercase letter and upper case letter. The length of the string is at most 100.
 
Output
For each test case, you must output the smallest times of typing the key to finish typing this string.
 
Sample Input
3
Pirates
HDUacm
HDUACM
 
Sample Output
8
8
8
 

题意:

有大写字母也有小写字母,她想尽可能少的敲键盘,可以按大写锁定键,可以按Shift键来进行敲字母

输出最少按键次数,注意,最后大写锁定键灯必须是灭的;

思路:把状态分为大写模式和小写模式进行dp

#include <cstdio>
#include <map>
#include <iostream>
#include<cstring>
#include<bits/stdc++.h>
#define ll long long int
#define M 6
using namespace std;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int moth[]={,,,,,,,,,,,,};
int dir[][]={, ,, ,-, ,,-};
int dirs[][]={, ,, ,-, ,,-, -,- ,-, ,,- ,,};
const int inf=0x3f3f3f3f;
const ll mod=1e9+;
int dp[][]; //0表示小写状态 1表示大写状态
int main(){
ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--){
string s; cin>>s;
int len=s.size();
dp[][]=;
dp[][]=;
for(int i=;i<=len;i++){
if(s[i-]>='a'&&s[i-]<='z'){
dp[i][]=dp[i-][]+; //如果是小写字母 自然是从小写状态+1最优
dp[i][]=min(dp[i-][]+,dp[i][]+); //大写状态则是由前一个大写状态用shift
//或者由小写状态的最优情况转成大写
}else{ //同理
dp[i][]=dp[i-][]+;
dp[i][]=min(dp[i-][]+,dp[i][]+);
}
}
cout<<min(dp[len][],dp[len][]+)<<endl;
}
}

hdu 2577 How to Type(dp)的更多相关文章

  1. HDU 2577 How to Type DP也可以模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=2577 大意: 大家都打过字吧,现在有个有趣的问题:给你一串字符串,有大写有小写,要求你按键次数最少来输出它,输出 ...

  2. HDU 2577 How to Type (DP,经典)

    题意: 打字游戏,求所按的最少次数.给出一个串,其中有大小写,大写需要按下cap键切换到大写,或者在小写状态下按shift+键,这样算两次,打小写时则相反.注意:在打完所有字后,如果cap键是开着的, ...

  3. HDU 2577 How to Type (线性dp)

    How to Type Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  4. HDU 2577 How to Type(dp题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2577 解题报告:有一个长度在100以内的字符串,并且这个字符串只有大写和小写字母组成,现在要把这些字符 ...

  5. hdu 2577 How to Type(DP)

    How to Type Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  6. HDU 2577 How to Type【DP】

    题意:给出一个字符串,有大写有小写,问最少的按键次数.然后打字的这个人有一个习惯,打完所有的字之后,指示灯要关闭. dp[i][j]表示打到第i个字母,j有0,1两个值表示指示灯开或者关的状态 然后就 ...

  7. HDU 2577 How to Type (字符串处理)

    题目链接 Problem Description Pirates have finished developing the typing software. He called Cathy to te ...

  8. HDU 2577 How to Type (字符串处理)

    题目链接 Problem Description Pirates have finished developing the typing software. He called Cathy to te ...

  9. DP问题(1) : hdu 2577

    题目转自hdu 2577,题目传送门 题目大意: 现给你n个区分大小写的字符串,大小写可用Caps Lock和shift切换(学过计算机的都知道) 但是有一点需要注意(shift是切换,若现在是大写锁 ...

随机推荐

  1. TCP 三次握手原理,你真的理解吗?

    最近,阿里中间件小哥哥蛰剑碰到一个问题——client端连接服务器总是抛异常.在反复定位分析.并查阅各种资料文章搞懂后,他发现没有文章把这两个队列以及怎么观察他们的指标说清楚. 因此,蛰剑写下这篇文章 ...

  2. 案例学Python--案例四:Django实现一个网站的雏形(2)

    续上篇,用Django创建了一个Web,我们肯定想展示自己的页面,简单点,我们想看到自己的HelloWorld.此处要从项目的配置说起,方法和路径配对了,展现页面分分钟的事情. 先上效果图吧:     ...

  3. C# 全屏坐标及区域坐标获取。自定义光标及系统光标描边捕捉显示。

    最近手头工作比较轻松了一点就继续研究和完善之前的录屏软件,使用AForge最大的问题在于:最原始的只能够录全屏,而自定义的录屏需要更改非常多的细节:like follows: 1.需要支持区域化录屏: ...

  4. MySQL数据库服务器(YUM)安装

    1. 概述2. 部署过程2.1 虚拟机console的NFS服务端配置2.2 虚拟机node15的NFS客户端配置2.3 虚拟机安装MySQL环境2.4 配置MySQL3. 错误及解决3.1 启动失败 ...

  5. JDK+JAVA+maven+IDEA

    JDK+JAVA https://jingyan.baidu.com/article/6dad5075d1dc40a123e36ea3.html maven+IDEA http://blog.csdn ...

  6. Wannafly挑战赛25 A.因子

    传送门 [https://www.nowcoder.com/acm/contest/197/A] 题意 给你n,m,让你求n!里有多少个m 分析 看这个你就懂了 [https://blog.csdn. ...

  7. VC++6.0的使用感想

    VC++6.0是我接触的第一款编程软件,一直以来都是使用这款软件来完成程序的编写,调试,运行.一直以来都是用C语言编写代码.而VC++6.0窗口简洁明了,占用资源少,上手容易,个人表示很喜欢. VC+ ...

  8. 对wordcount单词字母部分的修改

    原始代码: int s; s = ch; switch (s) { case 'a':letter[0]++; break; case 'b':letter[1]++; break; case 'c' ...

  9. 12.25daily_scrum

    今天是圣诞节,大家在度过了一个愉快的节日同时,同时也收到了最好的圣诞礼物,就是调试工作已经进入尾声,接下来我们组的主要任务就是M2阶段的总结了.为了更好的做好M2阶段的收官工作,我们组决定分配相当的一 ...

  10. Eclipse集成Tomcat报错:java.lang.OutOfMemoryError: PermGen space

    Eclipse集成Tomcat报错,使用Spring 4.3 框架,运行一段应用后,控制台报错: Unexpected death of background thread ContainerBack ...