题意:给出一个字符串,有大写有小写,问最少的按键次数。然后打字的这个人有一个习惯,打完所有的字之后,指示灯要关闭。

dp[i][j]表示打到第i个字母,j有0,1两个值表示指示灯开或者关的状态

然后就可以写出状态转移方程了,因为最后需要灯是灭的,所以最后在找最小值的时候,dp[len][1]需要加1

又一次看的题解===go--go

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; int dp[][];
char s[]; int main()
{
int ncase,i,len,ans;
scanf("%d",&ncase);
getchar();
while(ncase--)
{
memset(dp,,sizeof(dp));
ans=;
gets(s+);
len=strlen(s+);
dp[][]=;
dp[][]=;
for(i=;i<=len;i++)
{
if(s[i]>='A'&&s[i]<='Z')
{
dp[i][]=min(dp[i-][]+,dp[i-][]+);
dp[i][]=min(dp[i-][]+,dp[i-][]+);
}
else
{
dp[i][]=min(dp[i-][]+,dp[i-][]+);
dp[i][]=min(dp[i-][]+,dp[i-][]+);
}
}
ans=min(dp[len][],dp[len][]+);
printf("%d\n",ans);
}
}

HDU 2577 How to Type【DP】的更多相关文章

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

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

  2. HDU 2577 How to Type(dp题)

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

  3. HDU 1069—— Monkey and Banana——————【dp】

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  4. hdu 6169 gems gems gems【DP】

    题目链接:hdu 6169 gems gems gems Now there are n gems, each of which has its own value. Alice and Bob pl ...

  5. hdu 1078 FatMouse and Cheese【dp】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意:每次仅仅能走 横着或竖着的 1~k 个格子.求最多能吃到的奶酪. 代码: #include ...

  6. HDU - 1134 Game of Connections 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1134 题意 给出一个n 然后有2n个点 给两个点连一条边,最后连N条边,要求所有的边不能够交叉 问最多 ...

  7. HDU - 1160 FatMouse's Speed 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...

  8. HDU2577 How to Type【DP】

    题目链接: pid=2577">http://acm.hdu.edu.cn/showproblem.php? pid=2577 题目大意: 给你一个仅仅包括大写和小写字母的字符串,如今 ...

  9. hdu 2577 How to Type(DP)

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

随机推荐

  1. sql server 批量删除数据表

    SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Auth ...

  2. MySQL查看表占用空间大小(转)

    MySQL查看表占用空间大小(转) //先进去MySQL自带管理库:information_schema //自己的数据库:dbwww58com_kuchecarlib //自己的表:t_carmod ...

  3. ES6中的高阶函数:如同 a => b => c 一样简单

    作者:Sequoia McDowell 2016年01月16日 ES6来啦!随着越来越多的代码库和思潮引领者开始在他们的代码中使用ES6,以往被认为是"仅需了解"的ES6特性变成了 ...

  4. Python中编码问题?

    一.键盘输入 raw_input('请输入:'.decode('utf-8').encode('gbk'))raw_input(unicode('请输入:','utf-8').encode('gbk' ...

  5. Javascript获取URL参数值

    getQueryString: function (name) { var reg = new RegExp("(^|&)" + name.toLowerCase() + ...

  6. nested pop animation can result in corrupted navigation bar

    nested pop animation can result in corrupted navigation barFinishing up a navigation transition in a ...

  7. UITableView多选全选

    自定义cell和取到相应的cell就行了 TableViewCell.h #import <UIKit/UIKit.h> @interface TableViewCell : UITabl ...

  8. POJ 1468

    #include <iostream> #define MAXN 5005 using namespace std; struct node { int b_x; int b_y; int ...

  9. sql连接字符串的方法

    ----乌龟代码---合并列值 --********************************************************************************** ...

  10. Add and Search Word - Data structure design

    https://leetcode.com/problems/add-and-search-word-data-structure-design/ Design a data structure tha ...