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. [Python]Hamming distance 问题

    In [75]: x=4 In [76]: y=1 In [77]: str(bin(x ^ y))[2:].count('1') Out[77]: 2 In [78]: 来自:https://lee ...

  2. 机器学习 第五篇:分类(kNN)

    K最近邻(kNN,k-NearestNeighbor)算法是一种监督式的分类方法,但是,它并不存在单独的训练过程,在分类方法中属于惰性学习法,也就是说,当给定一个训练数据集时,惰性学习法简单地存储或稍 ...

  3. JDK1.7 HashMap 导致循环链表

    转载自:疫苗:JAVA HASHMAP的死循环 在淘宝内网里看到同事发了贴说了一个CPU被100%的线上故障,并且这个事发生了很多次,原因是在Java语言在并发情况下使用HashMap造成Race C ...

  4. vue开发小结(下)

    前言 继前几天总结了vue开发小结(上)后,发现还有很多的点没有能列举出来,于是还是打算新建一个下篇,再补充一些vue开发中需要注意的细节,确实还是都是细节的问题,我只是在这里强调下,希望对大家有帮助 ...

  5. VS2017登陆不了,TFS无法连接成功的问题

    由于使用的win7 64位操作系统,重装系统以后,安装了vs2017,登陆不成功,https://auth.gfx.ms/16.000.27887.2/OldConvergedLogin_PCore. ...

  6. confluence上传文件附件预览乱码问题(linux服务器安装字体操作)

    在confluence上传excel文件,预览时发现乱码问题主要是因为再上传文件的时候一般是Windows下的文件上传,而预览的时候,是linux下的环境,由于linux下没有微软字体,所以预览的时候 ...

  7. 词频统计 List Array

    c# 使用数组进行词频统计 1.先考虑要是使用的数据结构: Array在在内存中是连续存储的,所以它的索引速度非常快,而且赋值与修改元素也很简单,但是数组存在一些不足的地方.在数组的两个数据间插入数据 ...

  8. SE Springer小组之《Spring音乐播放器》可行性研究报告五、六

    5 可选择的其他系统方案 曾经考虑过制作闹钟系统,但考虑到闹钟系统在电脑应用中极其不实用,所以此方案未通过. 6 投资及效益分析 6.1支出 本软件只用于完成课程学习要求,不用做商用,无基础设备等支出 ...

  9. Linux&docker&cgroups

    cgroup https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_manage ...

  10. pandas数据统计

    1 count() 非空观测数量 2 sum() 所有值之和 3 mean() 所有值的平均值 4 median() 所有值的中位数 5 mode() 值的模值 6 std() 值的标准偏差 7 mi ...