hdu2577简单DP

来源:互联网 发布:岛风go软件打不开 编辑:程序博客网 时间:2024/05/17 01:27
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
3PiratesHDUacmHDUACM
 

Sample Output
888
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<map>#include<iomanip>#define INF 99999999using namespace std;const int MAX=101;int open_lock[MAX],close_lock[MAX];//分别代表输入当前这个字符并且大写键打开的情况下最少需要按的次数                                  //大写键没有打开的情况下最少需要按的次数. int main(){int t;string s;cin>>t;while(t--){cin>>s;open_lock[0]=1;int l=s.size();for(int i=0;i<l;++i){if(s[i]>='a' && s[i]<='z'){open_lock[i+1]=min(open_lock[i]+2,close_lock[i]+2);close_lock[i+1]=min(open_lock[i]+2,close_lock[i]+1);}else{open_lock[i+1]=min(open_lock[i]+1,close_lock[i]+2);close_lock[i+1]=min(open_lock[i]+2,close_lock[i]+2);}}cout<<min(open_lock[l]+1,close_lock[l])<<endl;}return 0;}


原创粉丝点击