It is Dandiya Night! A certain way how dandiya is played is described: There are N pairs of people playing at a time. Both the person in a pair are playing Dandiya with each other. Since a person might get bored with the same partner, he can swap wit…
Rainbow 6 is a very popular game in colleges. There are 2 teams, each having some members and the 2 teams play some matches against each other. The team which wins the maximum number of matches wins the game! Two of my friends Ashank and Aditya (bett…
GT and set Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description You are given N sets.The i−th set has Ai numbers. You should divide the sets into L parts. And each part should have at least one numbe…
http://acm.hdu.edu.cn/showproblem.php?pid=5745 这题好劲爆啊.dp容易想,但是要bitset优化,就想不到了. 先放一个tle的dp.复杂度O(n * m)的 第一个串,记作str[],第二个记作sub[] 思路就是,设dp[i][j][k]表示,匹配了sub的前i个,以str的第j个结尾,然后sub[i]有三种状态,0表示不变化,1表示和前一个,2表示和后一个. 那么以求dp[i][j][0]为列 因为需要的是判断str的第j个结尾是否和sub的前…
题目链接:hdu_5036_Explosion 题意: 一个人要打开或者用炸弹砸开所有的门,每个门里面有一些钥匙,一个钥匙对应一个门,有了一个门的钥匙就能打开相应的门,告诉每个门里面有哪些门的钥匙,问需要用的炸弹为多少.   思路: 考虑每个点需要用炸弹打开的概率,那么所有点的概率之和就是解.首先用bitset优化一个floyd,将每个门可以由那些门打开,就是有多少种方案,对于这个门的期望就是1/cnt,然后相加就行. PS:这里运用了bitset优化到了n^3/64. #include<bit…
bfs的时候用bitset优化一下. 水题 #include <cstdio> #include <cstring> #include <algorithm> #include <bitset> #include <queue> #include <unordered_map> using namespace std; ; int N,M; unordered_map<string,int> mp; bitset<m…
这题现场的数据出水了,暴力就能搞过. 标解是拿bitset做,转移的时候用bitset优化过的操作(与或非移位)来搞,复杂度O(N*M/w) w是字长 第一份标程的思路很清晰,然而后来会T. /*--------------------------------------------------------------------------------------*/ #include <algorithm> #include <iostream> #include <cs…
题目链接 思路 floyd求一下传递闭包,然后统计每个点可以到达的点数. 会tle,用bitset优化一下.将floyd的最后一层枚举变成bitset. 代码 /* * @Author: wxyww * @Date: 2019-01-23 15:08:40 * @Last Modified time: 2019-01-23 15:22:52 */ #include<cstdio> #include<iostream> #include<cstdlib> #include…
<题目链接> 题目大意:FJ想按照奶牛产奶的能力给她们排序.现在已知有N头奶牛$(1 ≤ N ≤ 1,000)$.FJ通过比较,已经知道了M$1 ≤ M ≤ 10,000$对相对关系.每一对关系表示为“X Y”,意指X的产奶能力强于Y.现在FJ想要知道,他至少还要调查多少对关系才能完成整个排序. 解题分析: 因为完全图只需要$n*(n-1)/2$对关系就能确定所有的所有节点的顺序,所以这里我们只需要求出传递闭包之后,能够确定的关系数,然后相减即可.因为本题 $n\leq10^3$,$O(n^3…
<题目链接> 题目大意:用用邻接矩阵表示一个有向图,现在让你求其中三元环的数量. 解题分析:先预处理得到所有能够直接到达每个点的集合$arrive[N]$和所有能够由当前点到达的集合$to[N]$.然后就是枚举三元环中的两个点$a,b$,然后再求$arrive[a]$与$to[b]$的交集,因为三元环中每个点都计算了一遍它所在所有三元环的数量,所以最后的答案就是所有点的交集之和/3.同时,因为$n\leq1500$,所以这里用到了bitset优化常数. #include <bits/st…