HDUOJ 2577 How to type
来源:互联网 发布:组策略禁止卸载软件 编辑:程序博客网 时间:2024/06/07 03:18
#ifdef _DEBUG#pragma warning(disable : 4996)#endif#include <iostream>#include <string>#include <vector>#include <stack>#include <queue>#include <deque>#include <set>#include <map>#include <algorithm>#include <functional>#include <sstream>#include <utility>#include <cstring>#include <cstdio>#include <cstdlib>#include <ctime>#include <cmath>#include <cctype>#define CLEAR(a, b) memset(a, b, sizeof(a))#define CLOSE() ios::sync_with_stdio(false)#define IN() freopen("in.txt", "r", stdin)#define OUT() freopen("out.txt", "w", stdout)#define PF(a) printf("%d\n", a)#define SF(a) scanf("%d", &a)#define SFF(a, b) scanf("%d%d", &a, &b)#define FOR(i, a, b) for(int i = a; i < b; ++i)#define LL long long#define MAXN 1005#define MAXM 1000010#define mod 1000007#define INF 1000000000using namespace std;//------------------------------------------------------------------------------------------////由记忆化到dpstring s;int dp[MAXN][2];int solve(int pos, bool cur) {int &ret = dp[pos][cur];if (ret) return ret;if (pos == s.size()) return 0;ret = 0;if (isupper(s[pos])) {if (cur) ret = min(solve(pos + 1, !cur) + 2, solve(pos + 1, cur) + 1);else ret = min(solve(pos + 1, cur), solve(pos + 1, !cur)) + 2;}else {if (cur) ret = min(solve(pos + 1, !cur), solve(pos + 1, cur)) + 2;else ret = min(solve(pos + 1, !cur) + 2, solve(pos + 1, cur) + 1);}if (pos == s.size() - 1 && cur) ret++;return ret;}int main() {int T; SF(T);while (T--) {CLEAR(dp, 0);cin >> s;dp[s.size()][0] = 0, dp[s.size()][1] = 1;for (int i = s.size() - 1; i >= 0; --i) {if (isupper(s[i])) {dp[i][1] = min(dp[i + 1][0] + 2, dp[i + 1][1] + 1);dp[i][0] = min(dp[i + 1][0], dp[i + 1][1]) + 2;}else {dp[i][1] = min(dp[i + 1][0], dp[i + 1][1]) + 2;dp[i][0] = min(dp[i + 1][1] + 2, dp[i + 1][0] + 1);}}PF(min(dp[0][0], dp[0][1]+1));}return 0;}
阅读全文
0 0
- HDUOJ 2577 How to type
- hdu 2577 How to Type
- HDU-2577-How to Type
- HDU 2577 how to type
- HDU 2577 How to Type
- hdu 2577 How to Type
- Hdu 2577 How to Type
- HDU 2577 how to type
- hdu 2577 How to Type
- DP-How to Type-2577
- hdu 2577 How to Type
- HDOJ 2577 How to Type
- HDU 2577 How to Type
- hdu 2577 How to Type
- HDU - 2577 How to Type
- hdu 2577 How to Type
- HDU - 2577 How to Type
- HDU 2577 How to Type
- linux cgroup代码学习(1)——cgroup介绍
- USB Type-C Configuration Channel (CC) pin function
- 1018. 锤子剪刀布 (20)
- java编程:设计一个动物声音“模拟器”,希望模拟器可以模拟许多动物的叫声
- CSS选择器的权重与优先规则
- HDUOJ 2577 How to type
- Docker
- 事件驱动编程以及内部类
- 棋盘问题
- 一步步实现:springbean的生命周期测试代码
- VS1013win32改为x64出错调整步骤
- Uva--188 Perfect Hash
- codeforces A. Key races
- tutorials 实例程序