题意:给定一个字符串s 现在让你用最小的花费 覆盖所有区间 思路:dp[i]表示前i个全覆盖以后的花费 如果是0 我们只能直接加上当前位置的权值 否则 我们可以区间询问一下最小值 然后更新 #include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const int N = 2e5+7; typedef long long ll; const ll mod…
F. Ant colony time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si…
题目:https://codeforces.com/contest/1216/problem/F 题意:一排有n个位置,我要让所有点都能联网,我有两种方式联网,第一种,我直接让当前点联网,花费为i,第二种,如果当前点的值为1,代表当前点可以放置一个路由器,范围 [i-k,i+k]都能连上网,花费为i,求最小花费是所有点都能连上网 思路:这个很容易看出是一个DP,我们设立dp[i],为前i个位置都能连上网的最小花费,因为设立一个路由器左右范围都可以联网,所以我们考虑设立路由器的右端点,如果i-k可…
题目:https://codeforces.com/problemset/problem/977/F 题意:一个序列,求最长单调递增子序列,但是有一个要求是中间差值都是1 思路:dp,O(n)复杂度,我们想一下O(n^2)时的最长递增子序列,我们第二个循环要遍历前面所有的如果大于长度就加1,代表以这个数结尾的最长长度是多少, 因为中间差值不定,所以我们遍历整个循环,这个题设置中间差值只能是1,所以我们递推式就可以是   dp[i]=max(dp[i],dp[i-1]+1),用map来映射值即可…
B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/427/B Description The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c…
链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard problem. You need to implement an extra module for brackets coloring in text. Your editor consists of a line with infinite length and cursor, which point…
题目链接:CF - R296 - d2 - D 题目大意 一个特殊的图,一些数轴上的点,每个点有一个坐标 X,有一个权值 W,两点 (i, j) 之间有边当且仅当 |Xi - Xj| >= Wi + Wj. 求这个图的最大团. 图的点数 n <= 10^5. 题目分析 两点之间右边满足 Xj - Xi >= Wi + Wj (Xi < Xj)       ==>     Xj  - Wj >= Xi + Wi (Xi < Xj) 按照坐标 x 从小到大将点排序.用…
题目链接 题目大意 给你一个长为d只包含字符'a','b','c','?' 的字符串,?可以变成a,b,c字符,假如有x个?字符,那么有\(3^x\)个字符串,求所有字符串种子序列包含多少个abc子序列 题目思路 假如没有问号,那么就是一个简单的dp \(dp[i][1]为前i个位置有多少个a\) \(dp[i][2]为前i个位置有多少个ab\) \(dp[i][3]为前i个位置有多少个abc\) 考虑 '?' 会对 dp 的转移产生什么影响,因为 '?' 可以将三种字母全部都表示一遍,所以到了…
D. Kay and Snowflake     After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of the roses. Now he likes to watch snowflakes. Once upon a time, he found a huge snowflake that has a form of the tree (connect…
https://codeforces.com/contest/1136/problem/E 题意 给你一个有n个数字的a数组,一个有n-1个数字的k数组,两种操作: 1.将a[i]+x,假如a[i]+k[i]>a[i+1],则a[i+1]要变成a[i]+k[i],直到某个a[j]+k[j]<=a[j+1] 2.询问某个区间的和 题解 利用题目性质将题目转化到你会的东西的性质 令\(t_i=k_1+..+k_{i-1},b_i=a_i-t_i\) \(a_i \geq a_{i-1} + k_{…
C. Replacement time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation…
D. Developing Game   Pavel is going to make a game of his dream. However, he knows that he can't make it on his own so he founded a development company and hired n workers of staff. Now he wants to pick n workers from the staff who will be directly r…
题意: 构造一个序列,满足m个形如:[l,r,c] 的条件. [l,r,c]表示[l,r]中的元素按位与(&)的和为c. 解法: 线段树维护,sum[rt]表示要满足到现在为止的条件时该子树的按位与和至少为多少. 更新时,如果val的pos位为1,那么整个区间的按位与和pos位也应该为1,否则与出来就不对了.(这是本题解题的核心) 那么此时更新 sum[rt] |= val 即可.然后再check一遍看是否满足所有条件即可. 代码: #include <iostream> #inclu…
D. Legacy time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy…
D. The Bakery   Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery. Soon the expenses started to overcome the income, so…
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are…
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Description You are given a set of size $m$ with integer elements between $0$ and $2^{n}-1$ inclusive. Let's build an undirected graph on these integers in…
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/contest/988/problem/E Description Polycarp lives on a coordinate line at the point x=0. He goes to his friend that lives at the point x=a. Polycarp can…
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60949 ....看不懂 设dp[i][j][l]表示前i位,左括号-右括号=j,匹配到l了 状态转移,枚举下一个要填的括号,用next数组求状态的l,分别转移 代码 #include<bits/stdc++.h> using namespace std; const int maxn = 207;…
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/problem/F Solution 设\(v_i\)表示第\(i\)个点的果子数,设\(b_i=v_i-\sum_{x\in son}v_x\),显然依题意要满足\(b_i\geqslant 0\). 根据差分的性质我们可以得到\(\sum b_i=x\). 假设我们硬点树上剩下了\(m\)个点,则…
前言:最近被线段树+简单递推DP虐的体无完肤!真是弱! A:简单题,照着模拟就可以,题目还特意说不用处理边界 B:二分查找即可,用lower_lound()函数很好用 #include<string.h> #include<math.h> #include<algorithm> #include<stdio.h> #include<math.h> #include<string> #include<iostream> us…
Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the follow…
F. Lizard Era: Beginning Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/problem/F Description In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana and Worrigan. Overall the…
F. st-Spanning Tree 题目连接: http://codeforces.com/contest/723/problem/F Description You are given an undirected connected graph consisting of n vertices and m edges. There are no loops and no multiple edges in the graph. You are also given two distinct…
F. Polycarp and Hay 题目连接: http://www.codeforces.com/contest/659/problem/F Description The farmer Polycarp has a warehouse with hay, which can be represented as an n × m rectangular table, where n is the number of rows, and m is the number of columns…
http://codeforces.com/contest/733/problem/F 题意:给你一些城市和一些路,每条路有不满意程度和每减少一点不满意程度的花费,给出最大花费,要求找出花费小于s的最小生成树中最小的不满意程度 题解:首先明确的是肯定只删除一条路然后其他的找最小生成树即可,但是直接搞复杂度O(m*mlogm)所以先prim扣出一颗最小生成树,然后枚举所有边删这条边,如果在最小生成树上,直接减到贡献即可,如果不在最小生成树上,那么加上这条边,树肯定有环了,我们用lca暴力的扣出这个…
题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的倍数,否则就舍弃掉,然后把没有舍弃的数的值加起来,求和的最大值; 43 2 15 9 就拿这个来说,当拿3当做第一个数时结果是3+15+9=27因为2不是3的倍数:当拿2作为第一个数时,结果是2+2+14+8=26因为3,15,9都不是2的倍数,所以只能减小;同理...求最大的和; 我们可以记录每个…
题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数就是答案. 要是符合条件的话,那这个数的大小一定是等于gcd(a[l]...a[r]). 我们求区间gcd的话,既可以利用线段树性质区间递归下去然后返回求解,但是每次查询是log的,所以还可以用RMQ,查询就变成O(1)了. 然后求解区间内有多少个数的大小等于gcd的话,也是利用线段树的性质,区间递…
题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数.区间最小gcd一定小于等于区间最小值.所以仅仅要先推断最小值是否是最小gcd.若是的话,就求出最小值的个数.然后用r-l+1-个数就可以. 对于以上信息.能够用线段树来维护.分别维护区间gcd,区间最小值以及区间最小值的个数. 代码例如以下: #include <iostream> #includ…