码迷,mamicode.com
首页 > 其他好文 > 详细

暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

时间:2015-08-03 14:21:44      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

 

题目传送门

 1 /*
 2     题意:删除若干行,使得n行字符串成递增排序
 3     暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小
 4 */
 5 /************************************************
 6 Author        :Running_Time
 7 Created Time  :2015-8-3 10:49:53
 8 File Name     :C.cpp
 9  *************************************************/
10 
11 #include <cstdio>
12 #include <algorithm>
13 #include <iostream>
14 #include <sstream>
15 #include <cstring>
16 #include <cmath>
17 #include <string>
18 #include <vector>
19 #include <queue>
20 #include <deque>
21 #include <stack>
22 #include <list>
23 #include <map>
24 #include <set>
25 #include <bitset>
26 #include <cstdlib>
27 #include <ctime>
28 using namespace std;
29 
30 #define lson l, mid, rt << 1
31 #define rson mid + 1, r, rt << 1 | 1
32 typedef long long ll;
33 const int MAXN = 1e2 + 10;
34 const int INF = 0x3f3f3f3f;
35 const int MOD = 1e9 + 7;
36 char s[MAXN][MAXN];
37 int n, m;
38 bool ok[MAXN][MAXN];
39 
40 int main(void)    {       //Codeforces Round #283 (Div. 2) C. Removing Columns
41     while (scanf ("%d%d", &n, &m) == 2) {
42         for (int i=1; i<=n; ++i)    {
43             scanf ("%s", s[i] + 1);
44         }
45         int ans = 0;    memset (ok, false, sizeof (ok));
46         bool flag = true;
47         for (int j=1; j<=m; ++j)    {
48             flag = true;
49             for (int i=2; i<=n; ++i)    {
50                 if (ok[i][i-1]) continue;
51                 if (s[i][j] < s[i-1][j])    {
52                     ans++;  flag = false;   break;
53                 }
54             }
55             if (flag)   {
56                 for (int k=2; k<=n; ++k)    {
57                     if (s[k][j] > s[k-1][j])    ok[k][k-1] = true;
58                 }
59             }
60         }
61         printf ("%d\n", ans);
62     }
63 
64     return 0;
65 }

 

暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

标签:

原文地址:http://www.cnblogs.com/Running-Time/p/4699107.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!