HDU 5890 Eighty seven(DP+bitset优化)】的更多相关文章

Eighty seven Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others) Problem Description Mr. Fib is a mathematics teacher of a primary school. In the next lesson, he is planning to teach children how to add numbers up. B…
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的前…
预处理,$01$背包,$bitset$优化. 可以预处理出每一种询问的答案,用$01$背包计算答案,$dp[i][j][k]$表示,前$i$个数字中,选择了$j$个,能否凑出$k$这个数字,可以开成$bitset<90>dp[55][12]$,第三维$bitset$位运算优化. $HDU$不稳,有时超时,有时通过. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #…
/** 题目:hdu5745 La Vie en rose 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5745 题意:题目给出的变换规则其实就是交换相邻元素, 并且每个元素最多交换一次. 思路: 那么一个O(nm)的dp其实十分显然, dp_{i,j,k} ​​ 表示匹配到s的第i个字符, p的第j个字符, j这一位的当前状态是k (0表示和前面交换, 1表示没有交换, 2表示和后面交换). 转移方程如下: dp[i][j][0] = dp[i-1…
这题现场的数据出水了,暴力就能搞过. 标解是拿bitset做,转移的时候用bitset优化过的操作(与或非移位)来搞,复杂度O(N*M/w) w是字长 第一份标程的思路很清晰,然而后来会T. /*--------------------------------------------------------------------------------------*/ #include <algorithm> #include <iostream> #include <cs…
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…
题目大意 给定一个长度为\(n(n \leqslant 500000)\)的数列,将其分割为连续的若干份,使得 $ \sum ((\sum_{i=j}^kC_i) +M) $ 最小.其中\(C_i\)为序列中的项的值,\(M\)为常数.$ j,k $ 表示在原序列中连续的某一段的起始位置和结束位置. 解题思路 考虑到\(n\)的范围巨大,肯定不能用\(O(n^2)\)的暴力DP,而贪心又显然有问题,所以我们只能尝试对DP优化. 我们设\(f[i]\)为前\(i\)项作为子问题的解,\(sum[i…
题目链接 Eighty seven 背包(用bitset预处理)然后对于每个询问O(1)回答即可. 预处理的时候背包. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i(a); i <= (b); ++i) #define dec(i, a, b) for(int i(a); i >= (b); --i) const int N = 52; int T, q, n; int f[…
Bipartite Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 840    Accepted Submission(s): 285 Problem Description Soda has a bipartite graph with n vertices and m undirected edges. Now he w…
艰难的一道题,体现出菜菜的我... 首先,先吐槽下. 这题到底出题人是怎么想的,用普通概率dp水过??? 那为什么我概率dp写的稍微烂点就一直tle?  感觉很不公平.大家算法都一致,因为我程序没有那么简练就过不了. 太坑了... 当然,说到底还是实力的问题,谁叫你不会一些常数级别的优化. 谁叫你写的时候不写的好一点. 比赛的时候在速度秒掉了最后两题后,卡这道题卡了4个多小时,也没有心情去看其他的题目了. 期间想了各种优化的方法. 最后因为一个小错误wa了N次后没有过而遗憾终身... 1. 直接…