Description Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected…
B. Marvolo Gaunt's Ring Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is sti…
B. Marvolo Gaunt's Ring 这种一般只有三个的都可以处理前缀和后缀,再枚举中间这个值. 这个和之前写过的C. Four Segments 前缀后缀 处理方式很像. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include <queue> #include <vector> #include <io…
855B - Marvolo Gaunt's Ring 思路:①枚举a[j],a[i]和a[k]分别用前缀最小值最大值和后缀最小值和后缀最大值确定. ②dp,dp[i][j]表示到第j为止,前i+1个值加起来的最大值. 代码: 代码①: #include<bits/stdc++.h> using namespace std; #define ll long long ; const int INF=0x3f3f3f3f; int a[N]; int premx[N]; int premn[N]…
[链接]h在这里写链接 [题意] 给你n个数字; 让你在其中找出三个数字i,j,k(i<=j<=k); 使得p*a[i]+q*a[j]+r*a[k]最大; [题解] /*     有一个要求i<=j<=k;     也就是说系数之间的下标是有关系的.     枚举第一个位置的下标i;         则第二个人j         i<=j<n         枚举中间那个人的位置在哪.     求出前i个位置,第一个人能获得的最大值是多少     求出后n-i个位置,第…
传送门 Description 给定三个数 \(p~,~q~,~r~\),以及一个数组 \(a\), 找出三个数 \(i~,~j~,~k\) ,其中 \(i~\leq~j~\leq~k\) 最大化 \(p~\times~a_i~+~q~\times~a_j~+~r~\times~a_r\) Input 第一行是数组长度 \(n\) 以及 \(p~,~q~,~r~\). 第二行 \(n\) 个数代表这个数组 Output 输出一个整数代表答案 Hint \(-10^5~\leq~n~\leq~10…
I.导入 求长度为\(\text{len}\)的包含给定连续子串\(\text{T}\)的 0/1 串的个数.(\(|T|<=15\)) 通常来说这种题目应该立刻联想到状压 DP 与取反集--这样就不用考虑大量重复情况的容斥问题.设\(f_{i,S}\)表示前\(i\)个字符.最后\(|T|\)个字符为\(S\).不包含给定连续子串的情况数,状态转移方程简单不述.时间复杂度 \(\Theta(2^{|T|}\text{len})\). II.巧妙利用利用失配树的序列DP 上述算法的时间复杂度相当…
题目链接:http://poj.org/problem?id=2752 题目大意:给你一串字符串s找到所有的公共前后缀,即既是前缀又是后缀的子串. 解题思路: 如图所示 假设字符串pi与jq为符合条件的一组公共前后缀,那么易得pi=jq,如下图所示 若在字符串pi内,pk1与k2i为公共前后缀,有因为pi=jq所以对应的k2i在字符串jq内有后缀k4q与其等价.所以pi内的公共前后缀等也是pq的公共前后缀,而i=next[q],显然是个递归. 所以,可以通过不断使pos=next[pos]进行递…
http://poj.org/problem?id=2752 [题意] 给定一个字符串,求这个字符串的所有公共前后缀的长度,按从小到达输出 [思路] 利用kmp的next数组,最后加上这个字符串本身 [AC] #include<iostream> #include<cstring> #include<string> #include<cstdio> #include<algorithm> using namespace std; typedef…
题意: 首先定义集合的F值为  这个集合里面最大值和最小值的差. 现给出一个拥有n个数的集合(没有相同的元素), 要求求出这个集合内所有子集的F的值的和.例如: {4.7}这个集合里面有子集{4}.{7}.{4, 7}, 则这些子集的F值分别为4-4=0.7-7=0.7-4=3, 所以最后的结果就是0+0+3 = 3! 以下分析引用至 : http://blog.csdn.net/dragon60066/article/details/72599167 分析: 不难想到要先使数组升序方便计算和思…