D. Dense Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols fr…
D. Dense Subsequence 题目连接: http://codeforces.com/contest/724/problem/D Description You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so that any contiguous subse…
传送门:D Dense Subsequence 题意:输入一个m,然后输入一个字符串,从字符串中取出一些字符组成一个串,要求满足:在任意长度为m的区间内都至少有一个字符被取到,找出所有可能性中字典序最小的情况,并按字典序输出 思路:字典序 例如 aaaaaaab < ab  也就是说,如果满足要求的取法中取到了b 那么所有的a都应该被取到,这样才可以保证字典序最小,那么也就是说在26个字母中找到一定要被取的最大字母,然后再确定最大的字母的个数,比它小的全部要取 AC代码: #include &quo…
Dense Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from…
[codeforces724D]Dense Subsequence 试题描述 You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected…
D. Dense Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols fr…
原文链接https://www.cnblogs.com/zhouzhendong/p/AGC026E.html 题目传送门 - AGC026E 题意 给定一个长度为 $2n$ 的字符串,包含 $n$ 个 $'a'$ 和 $n$ 个 $'b'$ . 现在,让你按照原顺序取出一些字符,按照原顺序组成新的字符串,输出所有满足条件的字符串中字典序最大的?(字典序: $'b'>'a'>'\ '$) 条件限制:当且仅当取了原序列的第 $i$ 个 $'a'$ 时,原序列的第 $i$ 个 $'b'$ 也被取了…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so th…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string s…
1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort    暴力枚举,水 1.题意:n*m的数组,每行最多可交换1次,列最多可交换两列,问最终是否可以变换到每行都是1~m. 2.总结:暴力即可. #include<bits/stdc++.h> #define F(i,a,b) for (int i=a;i<b;i++) #define FF(i,a,b) for (int i=a;i&l…
题目链接: http://codeforces.com/contest/724 A. Checking the Calendar time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given names of two days of the week. Please, determine whether it is…
链接:https://www.nowcoder.com/acm/contest/84/A 来源:牛客网 [出处]:http://codeforces.com/contest/196/problem/A [Codeforces Round #124 (Div. 1) A] 题目描述 给定字符串s,s只包含小写字母,请求出字典序最大的子序列. 子序列:https://en.wikipedia.org/wiki/Subsequence 字典序:https://en.wikipedia.org/wiki…
https://vjudge.net/problem/POJ-3617 这类字符串处理字典序问题经常用到贪心, 每决定输出一个字符之前,都要前后i++,j--逐个比大小,直至比出为止. #include<iostream> #include<cstdio> #include<queue> #include<cstring> #include<algorithm> #include<cmath> #include<set>…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1640 题意: 给你一个长度为n的字符串. 你可以将原串的首字母或尾字母移动到新串的末尾. 让你输出字典序最小的新串. 题解: 贪心. 三种情况: (1)c[head] < c[tail] 输出c[head],head++. (2)c[head] > c[tail] 输出c[tail],tail--. (3)c[head] == c[tail] 选head和tail并不等价. 比如原串为…
Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence ( a1, a2, ..., aN) be any sequence ( ai1, ai2, ..., aiK), where 1 <= i1 < i2 < ... < iK <= N.…
Hdu6586 字符串字典序贪心 题意 给出一个只包含26个字符的字符串(|S|<=1e5),要求从中取出长度为k的字典序最小的组序列,满足所给的26个字母的限制条件,例如\([l_i,r_i]\),表示i字符的数量关系限制 分析 1.对于构造字典序最小的序列,通常是一位一位构造的. 2.首先题目有限制条件,所以我们考虑一下什么条件时才满足限制条件. 我们从a开始取,每次碰到a,如果满足限制条件,我们肯定取上,这样才能满足字典序最小,那么限制条件是什么?什么时候停止取a转向去取b,我们对此进行思…
题意:E.Maximum Subsequence Value 题意: 给你n 个元素,你挑选k个元素,那么这个 k 集合的值为 ∑2i,其中,若集合内至少有 max(1,k−2)个数二进制下第 i 位为 1,则第 i 位有效,求一个集合可以得到的最大值. 题解: 应该是一种贪心 当k==3的时候,那么也就相当于从n个元素中挑选出来三个数进行或操作即可.如果你选择k==4,那么就相当于在k==3的基础上进行与操作,那么这个结果只会小于等于k==3时候的答案. k==5之后的也是这样 代码: 1 #…
原题链接:http://poj.org/problem?id=3617 问题梗概:给定长度为 的字符串 , 要构造一个长度为 的字符串 .起初, 是一个空串,随后反复进行下列任意操作. 从 的头部删除一个字符,加到 的尾部. 从 的尾部删除一个字符,加到 的尾部. 目的是要构造字典序尽可能小的字符串 .     限制条件: 字符串 只包含大写英文字母 输出的字符串每 80 个字符进行一次换行 字典序是指从前到后比较两个字符串大小的方法.首先比较第 1 个字符,如果不同则第 1 个字符较小的字符串…
题目描述 Best Cow Line (POJ 3617) 给定长度为N的字符串S,要构造一个长度为N字符串T.T是一个空串,反复执行下列任意操作: 从S的头部删除一个字符,加到T的尾部: 从S的尾部删除一个字符,加到T的尾部: 目标是要构造字典序尽可能小的字符串T. 限制条件 1 <= N <= 2000 字符串 S 只包含大写英文字母 样例输入 N = 6 S = "ACDBCB" 样例输出 ABCBCD (如下图所示进行操作) 思路分析 不断取S的开头和结尾中较小的一…
Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30684   Accepted: 8185 Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arranges his…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=465&page=show_problem&problem=2399 最长的很简单,将串翻转过来后求两个串的lcs就是答案.. 主要是字典序那里... 还是开string来比较吧.. 注意最后输出方案时用前半段推出后半段.(因为可能lcs时会重合...) #include <cstdio> #include…
题目链接 Solution Meet in the middle. 考虑到 \(2^{35}\) 枚举会超时,于是分成两半枚举(尽量平均). 然后不能 \(n^2\) 去匹配,需要用到一点贪心: 将数分成 \(p,q\) 两组,那么对于任意数 \(p_i\) ; 它与 \(q\) 数组中组成最大得到的值即为 最大的与 \(p_i\) 之和不超过\(m\) 的数. 然后就可以贪心优化了. 还要注意一点就是最大的两个也要考虑一次. Code #include<bits/stdc++.h> #def…
\(给定一串字母,分成k份,使得最大字典序最小.(字母可以任意组合)\) \(------------------------------issue~------------------------\) \(首先肯定先对字母排序,然后往k个盒子都丢一个字母(因为不能为空)\) \(那么接下来,就一定能够要想清楚了......\) \(\color{Red}Ⅰ.当接下来的字母都相等时,就均分到k个盒子里,因为这时候影响字典序的只是长度\) \(\color{Purple}{Ⅱ.当接下来的字母不全相…
原题链接:Best Cow Line 1. 问题描述 2. 输入 6 A C D B C B 3. 输出 ABCBCD 4.思路分析 不断地取原字符串 S 中开头和末尾比较小的字符串放到 T 的末尾 特殊情况:S 的开头和末尾一样,先放开头的还是结尾的字母.解决办法:将 S 反序排列得到 $S^{'}$ ,与 S 比较,哪个小,就放哪个 5. 代码 #include <iostream>#include<cstring> using namespace std; int n,i,j…
A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_back using namespace std; typedef long long ll; typedef unsigned long long ull; const ll LLmaxn = 2e18; int main() { string a; cin >> a; , c=; ; i <…
题意:给你一组数,每次可以选队首或队尾的数放入栈中,栈中元素必须保持严格单增,问栈中最多能有多少元素,并输出选择情况. 题解:首先考虑队首和队尾元素不相等的情况,如果两个数都大于栈顶元素,那么我们选小的放进去,否则选择比栈顶元素大的放进去,该题重点在于队首和队尾元素相同的情况,由于他们相同,那么我们如果将某一个数放进去后,因为栈中是严格单调的,那么假如我们选左边,那么右边就永远不可能再选了,同理选右边也是一样,所以我们在两边分别跑一下,求一个最长上升数组长度即可. 代码: int n; int…
D2. Optimal Subsequences (Hard Version) This is the harder version of the problem. In this version, 1≤n,m≤2⋅105. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a seque…
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][Status][Discuss] Description FJ打算带他的N(1 <= N <= 30,000)头奶牛去参加一年一度的“全美农场主大奖赛”.在这场比赛中,每个参赛者都必须让他的奶牛排成一列,然后领她们从裁判席前依次走过. 今年,竞赛委员会在接受队伍报名时,采用了一种新的登记规则:他们把所…
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求LCS,转移同时维护f[i][j].s为当前状态字典序最小最优解 f[n][n].s的前半部分一定是回文串的前半部分(想想就行了) 当s的长度为奇时要多输出一个(因为这样长度+1,并且字典序保证最小(如axyzb  bzyxa,就是axb|||不全是回文串的原因是后半部分的字典序回文串可能不是最小,多…
题目链接:http://codeforces.com/contest/724/problem/D 题意:给定一个字符串和一个数字m,选取一个一个子序列s,使得对于字符串中任意长度为m的子序列都至少含有s的位置(不是字符),求所有s在sort后字典序最小的那个字符串. 思路:对字符排序后,从最后一个开始贪心,判断删除该字符后是否符和题意,当删除后不符合题意时,贪心到该相同字符对应的第一个位置为止. 比如对于test3来说 排序后为a a a b b b b c c c c 删除到(b,6)时发现不…