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. Scala学习(六)---Scala对象

    Scala中的对象 摘要: 在本篇中,你将会学到何时使用Scala的object语法结构.在你需要某个类的单个实例时,或者想为其他值或函数找一个可以挂靠的地方时,你就会用到它.本篇的要点包括: 1. ...

  2. Ionic 入门与实战之第三章:Ionic 项目结构以及路由配置

    原文发表于我的技术博客 本文是「Ionic 入门与实战」系列连载的第三章,主要对 Ionic 的项目结构作了介绍,并讲解了Ionic 中的路由概念以及相关配置. 原文发表于我的技术博客 1. Ioni ...

  3. python常用程序算法

    一.冒泡排序: 1.冒泡排序是将无序的数字排列成从小到大的有序组合: 过程:对相邻的两个元素进行比较,对不符合要求的数据进行交换,最后达到数据有序的过程. 规律: 1.冒泡排序的趟数时固定的:n-1 ...

  4. spring-session-data-redis包冲突

    包冲突 spring 的包很容易冲突, 因为写软件的人在兼容性上处理的不够,一般不检测重复加载. spring-session-data-redis 引用后, 一定要把 spring-session ...

  5. Puppet常识梳理

    Puppet简单介绍 1)puppet是一种Linux/Unix平台下的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件.用户.cron任务.软件包.系统服务等.puppet把这些系统 ...

  6. android studio报Resolved versions for app (26.1.0) and test app (27.1.1)differ. 错误的解决办法

    https://blog.csdn.net/qq_36636969/article/details/80278150

  7. 我的software

    每个学计算机软件的同学都有可能经历以下的情况: 1.  哎,我家电脑开不了机了,来帮帮忙 2.  我耳机坏了,你给修修吧 3.  你能换手机屏不 4.  过来看下,我的Word打不开了 等等等等 这些 ...

  8. 无限级结构SQL查询所有的下级和所有的下级

    Id,PId无限级结构,查询某个Id的所有下级或所有上级,使用WITH AS查询 查找Id为1所有的下级 /*查找Id为1所有的下级*/ WITH T AS( SELECT Id,PId,Name,0 ...

  9. pandas修改全列的时间格式 无需使用apply

    df.date.dt.strftime('%Y%m%d') #实现全列修改时间格式

  10. js堆栈

    //栈只存地址 堆存对象和地址: 浅拷贝: 深拷贝: 队列类似于过道,走廊: