您的位置:首页 > 其它

hdu 2577 How to Type dp

2015-08-02 21:18 441 查看
题意:通过按最少次键盘数打出要求的字符,详见样例。

设dp【i】【0】表示关闭Caps lock情况下的打第i个字符时最少次数,dp【i】【1】为开启状态下的最少次数,

则有小写情况下:dp【i】【0】 = min(dp【i-1】【0】+1(小写情况下直接打),dp【i-1】【1】+2(按住shirt再打,比开启关掉大写再打再开启大写要优)),大写反一下就行了。

#include <bits/stdc++.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <time.h>
#include <vector>
#include <cstdio>
#include <string>
#include <iomanip>
///cout << fixed << setprecision(13) << (double) x << endl;
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define ls rt << 1
#define rs rt << 1 | 1
#define pi acos(-1.0)
#define eps 1e-8
#define Mp(a, b) make_pair(a, b)
#define asd puts("asdasdasdasdasdf");
typedef long long ll;
//typedef __int64 LL;
const int inf = 0x3f3f3f3f;
const int N = 110;

int dp
[2];
char a
;

int main()
{
	int tot, n;
	scanf("%d", &tot);
	while( tot-- ) {
		scanf("%s", a+1 );
		n = strlen( a+1 );
		memset( dp, 0, sizeof( dp ) );
		dp[0][1] = 1;
		for( int i = 1; i <= n; ++i ) {
			if( a[i] >= 'a' && a[i] <= 'z' ) {
				dp[i][0] = min( dp[i-1][0] + 1, dp[i-1][1] + 2 );
				dp[i][1] = min( dp[i-1][0] + 2, dp[i-1][1] + 2 );
			}
			else if( a[i] >= 'A' && a[i] <= 'Z' ) {
				dp[i][0] = min( dp[i-1][0] + 2, dp[i-1][1] + 2 );
				dp[i][1] = min( dp[i-1][0] + 2, dp[i-1][1] + 1 );
			}
		}
		dp
[1]++;
		printf("%d\n", min( dp
[0], dp
[1] ) );
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: