2016 Pacific Northwest Region Programming Contest—Division 2 Problem M
来源:互联网 发布:阿里云邮箱前缀怎么写 编辑:程序博客网 时间:2024/09/21 06:21
Problem M — limit 1 second Alphabet
A string of lowercase letters is called alphabetical if deleting zero or more of its letters can result in the alphabet string “abcdefghijklmnopqrstuvwxyz”.
Given a string s, determine the minimum number of letters to insert anywhere in the string to make it alphabetical.
Input
The input consists of a single line containing the string s (1 ≤|s|≤ 50). It is guaranteed that s consists of lowercase ASCII letters ‘a’ to ‘z’ only.
Output
Print, on a single line, a single integer indicating the minimum number of letters that must be inserted in order to make the string s alphabetical.
Sample Input Sample Output
xyzabcdefghijklmnopqrstuvw 3
Sample Input Sample Output
aiemckgobjfndlhp 20
2016 Pacific Northwest Region Programming Contest—Division 2
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
# define N 1000
int str[N+2][N+2];
int main()
{
int i,j,la,lb;
char str1[N+1]="abcdefghijklmnopqrstuvwxyz";
char str2[N+1];
scanf("%s",str2);
la=strlen(str1);
lb=strlen(str2);
for(i=0;i<=la;i++)
str[0][i]=0;
for(j=0;j<=lb;j++)
str[j][0]=0;
for(j=0;j<la;j++)//枚举断点
for(i=0;i<lb;i++)
{
if(str1[j]==str2[i]) str[i+1][j+1]=str[i][j]+1;
else str[i+1][j+1]=max(str[i][j+1],str[i+1][j]);
}
printf("%d\n",26-str[lb][la]);
return 0;
}
- 2016 Pacific Northwest Region Programming Contest—Division 2 Problem M
- 2016 Pacific Northwest Region Programming Contest—Division 2 Problem S — limit 1 second Gravity
- 2016 Pacific Northwest Region Programming Contest—Division 2 Problem R — limit 1 second Equality
- 2015 Pacific Northwest Region Programming Contest—Division 2 Problem P — Complexity(字符串、贪心)
- 2015-2016 ACM-ICPC Pacific Northwest Regional Contest Div.2( Problem V Gears)
- 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 2)
- Sichuan State Programming Contest 2011 —— D.Division
- Programming Contest Problem Types
- Programming Contest Problem Types
- 2015-2016 ACM-ICPC Pacific Northwest Regional Contest Div.2 全部题目题解
- 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 2)【solved:12 / 13】
- Sichuan University Programming Contest 2011 Preliminary(for Non-SCUers) / M A Simple Problem
- 【2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div 1)C】【排序 模拟】Classy 课程难度排序超多关键字
- Gym 101243 (2016-2017 ACM Central Region of Russia Quarterfinal Programming Contest)
- 2016-2017 ACM-ICPC Pacific Northwest Regional Contest
- [CF Gym 100827C] Containment [2014-2015 ACM-ICPC Pacific Northwest Regional Contest C]
- Programming Contest Problem Types Of IOI
- Sichuan University Programming Contest 2011 Preliminary(for Non-SCUers) / C A Coin Problem
- java数据类型基础,运算符,常量,变量
- 一些常用的框架相关名词解释与说明
- adb工具(通用的调试工具、debug工具)&操作命令详解
- matlab出现错误: Error using xlsread (line 247)Error: 服务器出现意外情况。
- 7218:献给阿尔吉侬的花束
- 2016 Pacific Northwest Region Programming Contest—Division 2 Problem M
- 题目1019:简单计算器
- shell练习题
- android_Zrevo目录结构
- MapReduce简介
- vector容器中iterator的使用
- 高斯消元
- [10] Linux系统日常运维
- 多行数据输出与处理