题目大意:给你长度为n的字符串(n<=1e6),让你对它进行划分,如果一段里面只有字母和

空格可以包含m(m<=1e5)个,如果有其他字符只能包含n个,问你最少需要分成几段。

思路:划分dp,dp[ i ] 表示以i为结束最少需要分成多少段,复杂度n*m,不能接受,我们考虑贪心

每次划分使其中包含的字符尽可能多,如果dp[ i ]没有赋值则直接跳过。

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
const int inf=0x3f3f3f3f;
char s[N],g[];
int n,m,dp[N],ans;
bool p[N];
bool judge(char x)
{
if(x>='a' && x<='z') return true;
if(x>='A' && x<='Z') return true;
if(x==' ') return true;
return false;
}
int main()
{
memset(dp,inf,sizeof(dp));
dp[]=;
ans=inf;
scanf("%d%d",&n,&m);
gets(g);
gets(s+);
int len=strlen(s+);
for(int i=;i<=len;i++)
{
if(dp[i]==inf) continue;
bool flag=true;
int up=m;
for(int j=;j+i<=len && j<=m;j++)
{
if(!judge(s[i+j])) flag=false,up=n;
if(j<=n && !flag)
{
int to=min(len,i+n);
dp[to]=min(dp[to],dp[i]+);
break;
}
else if(j>n && !flag)
{
int to=min(len,i+j-);
dp[to]=min(dp[to],dp[i]+);
break;
}
}
if(up==m) dp[min(i+m,len)]=min(dp[min(i+m,len)],dp[i]+);
}
//cout<<dp[3]<<endl;
printf("%d\n",dp[len]);
return ;
}

URAL - 1427-SMS的更多相关文章

  1. URAL 1427. SMS(DP+单调队列)

    题目链接 我用的比较传统的办法...单调队列优化了一下,写的有点搓,不管怎样过了...两个单调队列,存两个东西,预处理一个标记数组存... #include <iostream> #inc ...

  2. 1427. SMS

    http://acm.timus.ru/problem.aspx?space=1&num=1427 没想到这道题错了N遍  细节很重要呀 代码: #include<iostream> ...

  3. 1427. SMS(DP)

    1427 题意不太好理解 其它没什么 细心啊 细心 一个0写成了1 WA半天 以每个字符是以第一种方式还是第二种方式来D #include <iostream> #include<c ...

  4. JavaWeb-SpringBoot(抖音)_一、抖音项目制作

    JavaWeb-SpringBoot(抖音)_一.抖音项目制作 传送门 JavaWeb-SpringBoot(抖音)_二.服务器间通讯 传送门 JavaWeb-SpringBoot(抖音)_三.抖音项 ...

  5. Ural 1001 - Reverse Root

    The problem is so easy, that the authors were lazy to write a statement for it! Input The input stre ...

  6. [UWP]UWP中获取联系人/邮件发送/SMS消息发送操作

    这篇博客将介绍如何在UWP程序中获取联系人/邮件发送/SMS发送的基础操作. 1. 获取联系人 UWP中联系人获取需要引入Windows.ApplicationModel.Contacts名称空间. ...

  7. hihoCoder 1427 : What a Simple Research(大㵘研究)

    hihoCoder #1427 : What a Simple Research(大㵘研究) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 ...

  8. 一条SMS最大字符数,字符数达到多少按MMS处理

    1,一条SMS最大字符数 ----------------------------------------- android\frameworks\opt\telephony中 com.android ...

  9. Android网页中tel,sms,mailTo,Intent,Market协议用法总结

     tel:协议---拨打电话 <a href="tel:">调出拨号界面</a> <a href="tel:10086">调 ...

  10. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

随机推荐

  1. intellij idea 2018

    intellij idea 输入System.out.println()的快捷方法是:输入sout然后按tab键. 由于项目中引入了spring-boot-starter-test的依赖,也就是集成了 ...

  2. mac系统如何在桌面新建文件(夹)

    方法一:(终端方式,推荐) 1.在电脑上找到终端 2.指定你想要保存文件的路径,然后回车.例如桌面就是: cd desktop #或是 cd /Users/username/Desktop 有人问:假 ...

  3. C++中路径的处理方法(string)

    string 类提供字符串处理函数,利用这些函数,程序员可以在字符串内查找字符,提取连续字符序列(称为子串),以及在字符串中删除和添加.我们将介绍一些主要函数. 1.函数find_first_of() ...

  4. elasticsearch 基本配置

    基本配置elasticsearch的config文件夹里面有两个配置文件:elasticsearch.yml .logging.yml.jvm.options 第一个是es的基本配置文件,第二个是日志 ...

  5. kan

    http://blog.csdn.net/yahohi/article/details/7427724 http://duanhengbin.iteye.com/blog/1706635 http:/ ...

  6. centos6 python 安装 sqlite 解决 No module named ‘_sqlite3′

    原文连接: http://blog.csdn.net/jaket5219999/article/details/53512071 系统red hat6.7 也即centos6.7 python3.5. ...

  7. python - getattr 与 getattribute 机制

    #__getattribute__ class Foo(): def __init__(self,name): self.name = name def __getattr__(self, item) ...

  8. Android NDK编程

    1.首先需要声明native方法: public native String helloWorldNdk(); public native String hello_World_Ndk(); 2.然后 ...

  9. JS如何防止事件冒泡

    <div style="height:30px;line-height:30px;background:#FF0;text-align:center;" id="z ...

  10. 【python图像处理】图像的缩放、旋转与翻转

    [python图像处理]图像的缩放.旋转与翻转 图像的几何变换,如缩放.旋转和翻转等,在图像处理中扮演着重要的角色,python中的Image类分别提供了这些操作的接口函数,下面进行逐一介绍. 1.图 ...