1427

题意不太好理解 其它没什么 细心啊 细心 一个0写成了1 WA半天

以每个字符是以第一种方式还是第二种方式来D

1427. SMS(DP)-LMLPHP1427. SMS(DP)-LMLPHP

 #include <iostream>
#include<cstdio>
#include<algorithm>
#include<stdlib.h>
#include<cstring>
#include<vector>
using namespace std;
#define N 100010
char s[N];
int dp[N][],o[N][];
int judge(char x)
{
if(x==' ')
return ;
if(x>='a'&&x<='z')
return ;
if(x>='A'&&x<='Z')
return ;
return ;
}
int main()
{
int n,m,i,k=;
scanf("%d%d%*c",&n,&m);
gets(s);
k = strlen(s);
dp[][] = ;
o[][] = ;
if(judge(s[]))
{
dp[][] = ;
o[][] = ;
}
else
{
dp[][] = -;
o[][] = ;
}
for(i = ; i < k ; i++)
{
if(judge(s[i]))
{
if(o[i-][]>=m)
{
dp[i][] = min(dp[i-][]+,dp[i-][]+);
o[i][] = ;
}
else
{
if(o[i-][]&&dp[i-][]<dp[i-][]+)
{
dp[i][] = dp[i-][];
o[i][] = o[i-][]+;
}
else
{
dp[i][] = dp[i-][]+;
o[i][] = ;
}
}
}
else
o[i][] = ;
if(o[i-][]>=n)
{
if(o[i-][])
dp[i][] = min(dp[i-][]+,dp[i-][]+);
else
dp[i][] = dp[i-][]+;
o[i][] = ;
}
else
{
if(!o[i-][]||dp[i-][]<dp[i-][]+)
{
dp[i][] = dp[i-][];
o[i][] = o[i-][]+;
}
else
{
dp[i][] = dp[i-][]+;
o[i][] = ;
}
} }
if(o[k-][]!=)
printf("%d\n",min(dp[k-][],dp[k-][]));
else
printf("%d\n",dp[k-][]);
return ;
}
05-11 13:43