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. Spark在Windows下的环境搭建(转)

    原作者:xuweimdm   原文网址:http://blog.csdn.net/u011513853/article/details/52865076 由于Spark是用Scala来写的,所以Spa ...

  2. 2.RapidIO串行物理层的包与控制符号

    转自https://www.cnblogs.com/liujinggang/p/9932150.html 一.RapidIO串行物理层背景介绍 上篇博文提到RapidIO的物理层支持串行物理层与并行物 ...

  3. ZooKeeper 典型的应用场景——及编程实现

    如何使用 Zookeeper 作为一个分布式的服务框架,主要用来解决分布式集群中应用系统的一致性问题,它能提供基于类似于文件系统的目录节点树方式的数据存储,但是 Zookeeper 并不是用来专门存储 ...

  4. javascript DOM操作中的insertAdjacentHTML方法

    插入HTML内容与文本内容以前用的是innerHTML与innerText方法,今天看到insertAdjacentHTML和 insertAdjacentText两个API,特地学习一下: inse ...

  5. C_数据结构_递归自己调用自己

    # include <stdio.h> void f(int n) { ) printf("哈哈\n"); else f(n-i); } int main(void) ...

  6. python-小知识点-14

    ''' python2 python3 ''' #python2 print() print 'abc' range() xrange() 生成器 raw_input() #python3 print ...

  7. js实现随机的四则运算题目(2)-更新界面

    上次的代码提交完成后,有很多bug.比如函数会重复调用执行,每点击一次按钮都会在生成题目的下方直接生成新的题目,于是我在代码前面添加了如下的代码: function play_allE() { doc ...

  8. Linux内核分析第四章读书笔记

    第四章 进程调度 进程调度程序:确保进程能有效工作的一个内核子程序 决定将哪个进程投入运行,何时运行已经运行多长时间 进程调度程序可看做在可运行态进程之间分配有限的处理器时间资源的内核子系统 原则:只 ...

  9. 第二个spring,第五天

    陈志棚:成绩的统筹 李天麟:界面音乐 徐侃:代码算法 完成进度百分之70...会继续努力的!

  10. html 空白汉字占位符&#12288;

    在爬取京东评论时,复制html内容,发现文本中有些空格的宽度没见过.后来用htmlParser解析html页面时,发现这些空格都被替换为 . 12288是Unicode编码,&#表示宋体,&a ...