Codeforces 367
A. Sereja and Algorithm
水题不解释。
B. Sereja ans Anagrams
模p同余的为一组,随便搞。
C. Sereja and the Arrangement of Numbers
我还以为是找规律。。。
把每个数当成一个点。就有一个图。让后求欧拉路什么的。
D. Sereja and Sets
这个思路感觉很巧妙(可能是我太弱了),我们对于每一段连续的d,找到不包含它们的所有集合,这些集合的子集一定不可行。
见代码。
/*
* Problem: D. Sereja and Sets
* Author: Shun Yao
*/ #include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h> #include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <utility>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> //using namespace std; int n, m, d, bad[1 << 21], s[100010], cnt[25]; int main(/*int argc, char **argv*/) {
int i, j, k, l, tmp, ans; scanf("%d%d%d", &n, &m, &d);
for (i = 0; i < m; ++i) {
scanf("%d", &j);
for (k = 0; k < j; ++k) {
scanf("%d", &l);
s[l - 1] = i;
}
}
memset(bad, 0, sizeof bad);
for (i = 0; i < n; ++i) {
if (i >= d)
--cnt[s[i - d]];
++cnt[s[i]];
if (i >= d - 1) {
tmp = 0;
for (j = 0; j < m; ++j)
if (!cnt[j])
tmp += 1 << j;
bad[tmp] = 1;
}
}
ans = 21;
for (i = (1 << m) - 1; i >= 0; --i) {
if (!bad[i]) {
k = i;
l = 0;
while (k) {
++l;
k -= k & -k;
}
ans = std::min(ans, l);
} else {
k = i;
while (k) {
l = k & -k;
bad[i - l] = 1;
k -= l;
}
}
}
printf("%d", ans); fclose(stdin);
fclose(stdout);
return 0;
}
E. Sereja and Intervals
问题是求n个互不包含的区间且其中一个区间的左端是x的方案数。(原题n个区间排列也算不同方案,为了方便思考我们可以考虑排列算相同方案,然后让结果成以n的阶乘。
f[i][j][k]代表目前到i,有左端点j个,右端点k个的合法方案数。(好像还有其他的状态定义,也可以做)
Codeforces 367的更多相关文章
- Codeforces #367 (Div. 2) D. Vasiliy's Multiset (trie 树)
http://codeforces.com/group/1EzrFFyOc0/contest/706/problem/D 题目:就是有3种操作 + x向集合里添加 x - x 删除x元素,(保证存在 ...
- CodeForces #367 div2 D Trie
题目链接:Vasiliy's Multiset 题意:这里有一个set容器,有三种操作,+ num, - num, ? num,分别代表往容器里加上num,或者拿走num,或着从容器里找一个数temp ...
- CodeForces #367 div2 C
题目链接: Hard problem 题意:每个字符串可以选择反转或者不反转,给出反转每个字符串的代价,问使最少的代价使得这个字符串序列成字典序. dp[i][j] = x : 第一维是第i个字符串, ...
- CodeForces 367 C Sereja and the Arrangement of Numbers 欧拉回路
Sereja and the Arrangement of Numbers 题解: ummm. 在一副图中,如果全部点的度数是偶数/只有2个点是奇数,则能一笔画. 考虑图的点数k为奇数的时候,那么每个 ...
- Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset (0/1-Trie树)
Vasiliy's Multiset 题目链接: http://codeforces.com/contest/706/problem/D Description Author has gone out ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- trie树 Codeforces Round #367 D Vasiliy's Multiset
// trie树 Codeforces Round #367 D Vasiliy's Multiset // 题意:给一个集合,初始有0,+表示添加元素,-去除元素,?询问集合里面与x异或最大的值 / ...
随机推荐
- set集合_变长
//set可变集合 //便利初始化函数分配大小 NSMutableSet *mutableSet1 = [[NSMutableSet alloc] initWithCapacity:3]; NSMut ...
- public View getView(int position, View convertView, final ViewGroup parent)三个参数的意思
最近看到有人在问这三个参数的含义,其实帮助已经很详细的介绍了这三个参数,看来还是要好好学学英语了,不然连解释都看不懂. /** * Get a View that displays the d ...
- 关于Linux的windows目录的挂载
今天,linux主机下面要增加一点空间,不想再增加硬盘,所以就在实体机里面就设置了目录共享,添加自己系统的默认账号(为了增加自己主机的安全性,我都是设置的含有标点符号的密码---这也是这次挂载不成功的 ...
- MyEclipse Blue Edition 6.5 注册码生成程序
import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; im ...
- Hibernate--基本映射标签和属性介绍
一.映射文件的基本结构举例: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hiberna ...
- 我的MYSQL学习心得
我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(五) 运 ...
- 在oracle中where 子句和having子句中的区别
在oracle中where 子句和having子句中的区别 1.where 不能放在GROUP BY 后面 2.HAVING 是跟GROUP BY 连在一起用的,放在GROUP BY 后面,此时的作用 ...
- hdu 4920 Matrix multiplication (矩阵计算)
题目链接 题意:给两个矩阵a, b, 计算矩阵a*b的结果对3取余. 分析:直接计算时间复杂度是O(n^3),会超时,但是下面第一个代码勉强可以水过,数据的原因. #include <iostr ...
- MyBatis 实践 -动态SQL/关联查询
MyBatis 实践 标签: Java与存储 动态SQL 动态SQL提供了对SQL语句的灵活操作,通过表达式进行判断,对SQL进行拼接/组装. if 对查询条件进行判断,如果输入参数不为空才进行查询条 ...
- 缺少编译器要求的成员“System.Runtime.CompilerServices.ExtensionAttribute..ctor” 解决方案
我自己使用的解决方法 错误产生环境及非完美解决办法 错误提示:缺少编译器要求的成员"System.Runtime.CompilerServices.ExtensionAttribute..c ...