hdu 2577 How to Type(DP水)

这不是轻工校赛那个题么~~~~~!!!!!!!!

当时比赛我们都没咋想清楚,他俩脑子混沌中,我一激动,拿优先队列+BFS+剪枝过了 = =。。。后来知道数据很弱,不需要剪枝。。。- - 。。。后来知道这是DP题。。。后来我也拿DP过了。。。

今天又遇到了,脑子已经清楚很多了。

两个状态,大写锁定开,大写锁定关。然后推后一个状态取最小值即可。

因为这个最后她还要把大写锁定给关了,那就需要最后再加一取下大小。

#include <queue>
#include <stack>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define BUG puts("here!!!")

using namespace std;

const int MAX = 110;
char s[MAX];
int dp[2][MAX];
// 0  大写不锁定,1 大写锁定。 
int main()
{
	int ncases;
	
	scanf("%d",&ncases);
	
	while( ncases-- )
	{
		scanf("%s", s);
		int n = strlen(s);
		
		if( isupper(s[0]) )
		{
			dp[0][0] = 2;
			dp[1][0] = 2;
		}
		else
		{
			dp[0][0] = 1; 
			dp[1][0] = 2;
		}
		
		for(int i=1; i<n; i++)
		{
			if( isupper(s[i]) )
			{
				dp[0][i] = min(dp[0][i-1]+2, dp[1][i-1]+2);
				dp[1][i] = min(dp[0][i-1]+2, dp[1][i-1]+1);
			}
			else
			{
				dp[0][i] = min(dp[0][i-1]+1, dp[1][i-1]+2);
				dp[1][i] = min(dp[0][i-1]+2, dp[1][i-1]+2);
			}
		}
		printf("%d\n",min(dp[0][n-1], dp[1][n-1]+1));	
	}

return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值