HDU 2577 How to Type(dp)
来源:互联网 发布:淘宝领取淘金币 编辑:程序博客网 时间:2024/05/21 10:08
题目链接:HDU 2577 How to Type
dp。
notlock[i]表示type第i个字母后大写锁定键为关闭状态的最少type次数,lock[i]表示type第i个字母后大写锁定键为开启状态的最少type次数。
状态转移方程:
s[i]为大写字母:
lock[i] = min(lock[i - 1] + 1,notlock[i - 1] + 2);
notlock[i] = min(notlock[i - 1] + 2,lock[i - 1] + 2);
s[i]为小写字母:
lock[i] = min(lock[i - 1] + 2,notlock[i - 1] + 2);
notlock[i] = min(lock[i - 1] + 2,notlock[i - 1] + 1);
最后输出时候需要判断一下notlock[len - 1] 和 lock[len - 1] + 1的大小。
#include <iostream>#include <cstring>using namespace std;const int MAX_N = 100 + 10;int notlock[MAX_N],lock[MAX_N];int t;char s[MAX_N];int main(){ cin >> t; while(t--) { memset(notlock,0,sizeof(notlock)); memset(lock,0,sizeof(lock)); cin >> s; int len = strlen(s); if(s[0] >= 'A' && s[0] <= 'Z') lock[0] = notlock[0] = 2; else { lock[0] = 2; notlock[0] = 1; } for(int i = 1;i < len;i++) { if(s[i] >= 'A' && s[i] <= 'Z') { lock[i] = min(lock[i - 1] + 1,notlock[i - 1] + 2); notlock[i] = min(notlock[i - 1] + 2,lock[i - 1] + 2); } else { lock[i] = min(lock[i - 1] + 2,notlock[i - 1] + 2); notlock[i] = min(lock[i - 1] + 2,notlock[i - 1] + 1); } } cout << (notlock[len - 1] < lock[len - 1] + 1 ? notlock[len - 1] : lock[len - 1] + 1) << endl; } return 0;}
0 0
- HDU 2577 How To Type DP
- hdu 2577 How to Type(DP)
- hdu 2577 How to Type(DP)
- HDU 2577 How to Type (dp)
- HDU 2577 How to Type(dp)
- 【DP】HDU 2577 How to Type
- HDU-2577 How to Type DP
- hdu 2577 How to Type (dp)
- 【DP|水】HDU-2577 How to Type
- HDU 2577 How to Type (dp)
- hdu 2577 How to Type(dp)
- HDU 2577 How to Type (线性dp)
- hdu 2577 How to Type(DP)
- hdu 2577 How to Type dp
- [HDU 2577 How to Type]DP
- HDU 2577 How to Type(DP)
- HDU 2577 How to Type DP
- hdu 2577 How to Type (dp)
- 加法减法,微信也不好做
- java.util.concurrent小结
- VS2008项目相关文件介绍
- How To Build Your First F**king STAF Service
- 对于一个整数矩阵,存在一种运算,对矩阵中任意元素加一时,需要其相邻(上下左右)某一个元素也加一, 现给出一正数矩阵,判断其是否能够由一个全零矩阵经过上述运算得到。
- HDU 2577 How to Type(dp)
- CSS2写三角形
- Linux操作系统基础理论(5)-----EXT2文件系统的实现机制
- 如何快速有效读书
- iOS网络编程 ASIHTTPRequest 详解, http 请求终结者
- 获取中文字符串的拼音
- spring pointcut
- centos6.3 更新yum 源
- XAML的Resource和Style