Removing Columns 分类: 贪心 CF 2015-08-08 16:10 10人阅读 评论(0) 收藏
Removing Columns
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table
abcd
edfg
hijk
we obtain the table:
acd
efg
hjk
A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Input
The first line contains two integers — n and m (1 ≤ n, m ≤ 100).
Next n lines contain m small English letters each — the characters of the table.
Output
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
Sample test(s)
Input
1 10
codeforces
Output
0
Input
4 4
case
care
test
code
Output
2
Input
5 4
code
forc
esco
defo
rces
Output
4
Note
In the first sample the table is already good.
In the second sample you may remove the first and third column.
In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).
Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
判断每一列的字符是不是符合,如果符合则判断如果上一行的字符大余这一行,则标记一下,因为后面的无论是否符合,此时的字典序已将符合.
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-9
#define LL long long
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define CRR fclose(stdin)
#define CWW fclose(stdout)
#define RR freopen("input.txt","r",stdin)
#pragma comment(linker,"/STACK:102400000")
#define WW freopen("output.txt","w",stdout)
const int Max = 160000;
char s[110][110];
bool vis[110][110];
int n,m;
bool Judge(int j)
{
for(int i=1;i<n;i++)
{
if(!vis[i][i+1])
{
if(s[i][j]>s[i+1][j])
{
return true;
}
}
}
for(int i=1;i<n;i++)
{
if(!vis[i][i+1])
{
if(s[i][j]<s[i+1][j])
{
vis[i][i+1]=true;
}
}
}
return false;
}
int main()
{
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%s",s[i]);
}
int ans=0;
memset(vis,false,sizeof(vis));
for(int i=0;i<m;i++)
{
if(Judge(i))
{
ans++;
}
}
printf("%d\n",ans);
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
Removing Columns 分类: 贪心 CF 2015-08-08 16:10 10人阅读 评论(0) 收藏的更多相关文章
- DZY Loves Chemistry 分类: CF 比赛 图论 2015-08-08 15:51 3人阅读 评论(0) 收藏
DZY Loves Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Mahout快速入门教程 分类: B10_计算机基础 2015-03-07 16:20 508人阅读 评论(0) 收藏
Mahout 是一个很强大的数据挖掘工具,是一个分布式机器学习算法的集合,包括:被称为Taste的分布式协同过滤的实现.分类.聚类等.Mahout最大的优点就是基于hadoop实现,把很多以前运行于单 ...
- Task schedule 分类: 比赛 HDU 查找 2015-08-08 16:00 2人阅读 评论(0) 收藏
Task schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- android开发之broadcast学习笔记 分类: android 学习笔记 2015-07-19 16:33 32人阅读 评论(0) 收藏
android中的广播用的太多了,今天稍微总结一下. 按注册方式分为两种: 1.静态注册广播: 静态注册广播就是在androidManifest.xml文件中注册广播,假设我们要实现这样一个效果,在一 ...
- AndroidManifest.xml中的application中的name属性 分类: android 学习笔记 2015-07-17 16:51 116人阅读 评论(0) 收藏
被这个不起眼的属性折磨了一天,终于解决了. 由于项目需要,要合并两个android应用,于是拷代码,拷布局文件,拷values,所有的都搞定之后程序还是频频崩溃,一直没有找到原因,学android时间 ...
- JavaScript概念之screen/client/offset/scroll/inner/avail的width/left 分类: JavaScript HTML+CSS 2015-05-27 16:42 635人阅读 评论(0) 收藏
原文地址:http://caibaojian.com/js-name.html JS中获取各种宽度和距离,常常让我们混淆,各种浏览器的不兼容让我们很头疼,现在就在说说js中有哪些宽度和距离. 1.名词 ...
- OC基础:内存(内存管理) 分类: ios学习 OC 2015-06-25 16:50 73人阅读 评论(0) 收藏
自动释放池: @autoreleasepool { } 内存管理机制 谁污染,谁治理 垃圾回收机制:gc(Garbage collection),由系统管理内存,开发人员不需要管理. OC ...
- window.onload,<body onload="function()">, document.onreadystatechange, httpRequest.onreadystatechang 分类: C1_HTML/JS/JQUERY 2014-08-06 16:47 558人阅读 评论(0) 收藏
部分内容参考:http://www.aspbc.com/tech/showtech.asp?id=1256 在开发的过程中,经常使用window.onload和body onload两种,很少使用do ...
- JavaScript中的一些细节 分类: C1_HTML/JS/JQUERY 2014-08-05 16:45 384人阅读 评论(0) 收藏
1.设置id / class等属性 用 setAttribute 设置一些常规属性如 id ,className 的时候经常不起作用,只能用 object.id = value 这样来设置 news_ ...
- Brush Mode --- Nyoj 737 分类: Brush Mode 2014-03-25 08:10 202人阅读 评论(0) 收藏
石子合并(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 有N堆石子排成一排,每堆石子有一定的数量.现要将N堆石子并成为一堆.合并的过程只能每次将相邻的两堆 ...
随机推荐
- Java基础之写文件——使用Formatter对象加载缓冲区(UsingAFormatter)
控制台程序,使用Formatter对象将写入文件的数据准备好. 使用Formatter对象的format()方法,将数据值格式化到视图缓冲区charBuf中. import static java.n ...
- ubuntu14.04安装eclipse
1.安装jdk7.x,参考上篇<Linux14.04安装JDK> 2下载eclipse.tar 3.sudo tar -zxvf eclipse-x-x-.tar.gz mv eclips ...
- bash 截取字符串
转载自http://blog.chinaunix.net/uid-1757778-id-3162034.html 命令的2种替换形式 $()和 ``示例:截断字符串 a): #截取文件名称 ...
- JavaScript——DOM操作——Window.document对象
一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a =docunment.getElementById(&qu ...
- js拖拽换位置,使用数组方法
之前一直需要一个拖拽效果,网上找了些感觉不是不好用,就是写的有些地方让人不太满意,下面贡献一个自己写的.亲测可用,拖动后可互换位置!(带有注释) 方法/步骤 CSS代码部分 <style> ...
- 夺命雷公狗---DEDECMS----16dedecms取出首页今日更新
我们这次就要来取出我们的电影和电视剧以及综艺节目: 我们首先在我们受页面的模版文件中获取电影和电视剧的标签: 我们发现这里有一大堆,我只留一个即可: 然后我们到后台更新下首页的模版,看下是否只有一个模 ...
- SSH+DWZ、JQuery-UI ,swfobject.embedSWF属性与用法,IE下日期控件被flash控件挡住
---恢复内容开始--- 最近在做SSH+DWZ(JQuery-UI)项目,在用到图表问题的时候,出现在IE下面,日期控件被flash被挡住而不能选取日期情况,经在网络搜查,现在解决办法如下: 1.首 ...
- OpenStack 多台计算节点时的问题
Contents [hide] 1 前言 2 bug 3 解决方法 4 网络问题 前言 添加一台计算节点后无法创建虚拟机.在调度层就错误: bug https://review.openstack.o ...
- Jsoup的demao
package com.ch.jsoupdemo; import java.io.IOException; import org.jsoup.Jsoup;import org.jsoup.nodes. ...
- 五分钟打造自己的sql性能分析工具
1.首先要有一个trace文件 2. 打开trace文件 3. 另存为跟踪表 4.登录你要保存到的目标sqlserver服务器 5. 选择要保存的数据库和表名称 6. 保存完成(左下角出现进度直到显示 ...