CF-358D-Dima and Hares【T^T+*^*】】的更多相关文章

题目链接:http://codeforces.com/problemset/problem/358/D 题意: 有n个物品A[i]摆成一排,你要按照某一个顺序将它们全部取走. 其中,取走A[i]的收益为: (1)若A[i-1]和A[i+1]都没被取走,则收益为a[i] (2)若A[i-1]和A[i+1]被取走了一个,则收益为b[i] (3)若A[i-1]和A[i+1]都被取走,则收益为c[i] 注:将A[1]的左边和A[n]的右边视为永远有一个取不走的物品. 问你最大收益是多少. 题解: 表示状…
题目链接:http://codeforces.com/problemset/problem/358/D 开始题意理解错,整个就跪了= = 题目大意:从1到n的位置取数,取数的得到值与周围的数有没有取过有关,所有数都要取,求最终得到的最大结果 解题思路:dp题,转移方程如下 dp[i][0]=max(dp[i-1][0]+b[i-1],dp[i-1][1]+c[i-1]) dp[i][1]=max(dp[i-1][0]+a[i-1],dp[i-1][1]+b[i-1]) a,b,c分别表示周围没有…
有N<3000只宠物要喂,每次只能喂一只,每喂一只宠物,宠物的满足度取决于: 1 紧靠的两个邻居都没喂,a[i] 2 邻居中有一个喂过了,b[i] 3 两个邻居都喂过了,c[i] 把所有宠物喂一遍,得到的满足度之和最大为多少. =========== 动态规划, 动态转移方程的难点 在于 搞清楚“无后效性” =========== dp[i]为从i开始往后喂 以第一只宠物为例,可以选择 1) 先喂第一只, a[1] + 第二只排在第一只后面的最大值.注意,先喂第一只,只会影响第二只. 2)先喂第…
http://codeforces.com/contest/358/problem/D 题意:ai代表相邻的两个野兔都没有吃食物情况下的快乐系数,bi代表的是在相邻的两个野兔中有一个吃到食物的快乐系数,ci代表的是相邻的两个野兔都迟到事物的快乐系数,给你n个野兔的快乐系数,求最大快乐系数. dp[i][0]表示先于i+1个吃到食物的最大快乐系数,dp[i][1]表示后于i+1个吃到食物的最大快乐系数. #include <cstdio> #include <cstring> #in…
http://codeforces.com/contest/358/problem/D 题意:给出n个数,每个数取走的贡献与相邻的数有关,如果取这个数的时候,左右的数都还没被取,那么权值为a,如果左右两个数有一个被取走了,那么权值为b,如果左右两个数都被取走了,那么权值为c,求取取走全部数的最大值. 思路:f[i][1][0]代表这个位置在i-1选后才选,f[i][1][1]代表这个位置在i+1选后才选,f[i][0][0]代表这个位置在3个中是第一个选的,f[i][2][0]代表这个位置在3个…
从本质入手,这个东西影响取值的就是相邻两个哪个先取 设f[i][0/1]为前i个(i-1,i)中先取i/i-1的值(这里不算上i的贡献 转移就显然了,注意要先复制-inf #include<iostream> #include<cstdio> using namespace std; const int N=3005; int n,a[N],b[N],c[N],f[N][2]; int main() { scanf("%d",&n); for(int i…
dp[i][0]表示i号兔子先于i-1号兔子喂食,dp[i][1]反过来. 倒着DP D. Dima and Hares time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Dima liked the present he got from Inna very much. He liked the present he got…
CF358D Dima and Hares 洛谷评测传送门 题目描述 Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more. Dima felt so grateful to Inna about the present that he decided to buy her nn hares. Inna was very happy. She l…
CF 1405E Fixed Point Removal[线段树上二分]  题意: 给定长度为\(n\)的序列\(A\),每次操作可以把\(A_i = i\)(即值等于其下标)的数删掉,然后剩下的数组拼接起来,问最多能删多少个数 \(q\)次独立询问,每次把前\(x\)个数和\(后\)后\(y\)个数置为\(n+1\)之后解决上述问题 题解: 先不考虑把前\(x\)个数和后\(y\)个数置成\(n+1\)的情况 首先我们可以想到的是把所有数的值减去其下标,定义\(B_i = A_i - i\),…
[链接]:CF/4892 [题意]: 一个人解决n个问题,这个问题的值比k小, 每次只能解决最左边的或者最右边的问题 解决了就消失了.问这个人能解决多少个问题. [代码]: #include<bits/stdc++.h> #define PI acos(-1.0) #define pb push_back #define F first #define S second #define debug puts #define setp cout << fixed << s…
[文章标题打着转载,是因为不是自己想出来的解题,但下面的文字是自己敲的[~捂脸*>_<*~]] 题目就不贴了~~~DP+greedy的题.弱爆了看别人的代码思路过的.T^T但还是自己复述一遍吧~~ 刚开始看题目有点下不了手,不知道该怎么喂傲娇的小兔纸才好. 然后看了解题才知道,哦,原来是酱紫:就是喂某只小兔纸,可是收获的那只兔纸快乐值跟周围的兔纸有木有喂饱有关~~然后全部兔纸都要喂. dp转移方程如下: dp[i][0] = max(d[i-1][0] + b[i-1],d[i-1][1] +…
http://codeforces.com/contest/366/problem/D 遍历下界,然后用二分求上界,然后用dfs去判断是否可以. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 10000 using namespace std; int n,m; int head[maxn]; bool vis[maxn]; int e; int pl[maxn],pr[ma…
B. The Festive Evening time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather he…
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the u…
Polycarp is practicing his problem solving skill. He has a list of n problems with difficulties a1,a2,-,an, respectively. His plan is to practice for exactly k days. Each day he has to solve at least one problem from his list. Polycarp solves the pro…
You are given three integers a, b and x. Your task is to construct a binary string s of length n=a+b such that there are exactly a zeroes, exactly b ones and exactly x indices i (where 1≤i<n) such that si≠si+1. It is guaranteed that the answer always…
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways,…
CF 1400F.x-prime Substrings 题意: 给定一个由\('1'\)到\('9'\)组成的字符串\(s\)和一个数\(x\),定义一个串为\(x-prime\)串,当且仅当这个串上的数字和为\(x\),且任意一个不等于本身的子串的和都不是\(x\)的因子,问最少删多少个数字可以使得串\(s\)的任何子串都不是\(x-prime\)串 \(1 \le |s| \le 1000,1 \le x \le 20\) 题解: 由于\(x\)很小,所以我们可以枚举所有\(x-prime\…
题目链接:http://codeforces.com/problemset/problem/366/E 题意:给出一个n*m的数字矩阵A,每个矩阵元素的范围[1,K].给出一个长度为s的数字串B,B的每个元素的范围[1,K].将B中的每个元素t用A中的一个位置(i,j)代替,满足A[i][j]=B[t].这样就得到一个长度为s的位置序列.定义相邻两个位置的距离为曼哈顿距离,定义序列的最大距离为每两个相邻元素距离最大值.求一种替换方案使得序列的最大距离最大. 思路:最后转化成两个位置集合S1,S2…
http://codeforces.com/contest/366/problem/E |x1-x2|+|y1-y2|有四种情况 1.-(x1-x2)+(y1-y2); 2.(x1-x2)-(y1-y2); 3.-(x1-x2)-(y1-y2); 4.(x1-x2)+(y1-y2); 可以先把没一个数的坐标分为上面的四种情况存起来,然后在S序列相邻的两个数的曼哈顿距离最大就是两个数中的一个数的四种情况最大值减去另一个数的最小值. #include <cstdio> #include <c…
http://codeforces.com/contest/366/problem/C 转化为背包问题,可以将a[i]-b[i]*k看成重量,a[i]为价值: 因为a[i]-b[i]*k可以为负数,所以应该分开讨论.结果就是dp[10000],如果等于0则输出-1,否则输出dp[10000]; #include <cstdio> #include <cstring> #include <algorithm> #define maxn 500005 using names…
http://codeforces.com/contest/366/problem/B 从0到k枚举起点,然后i+k判断是不是i+k>=n如果是i=(i+k)%n;否则i=i+k; #include <cstdio> #include <cstring> #include <algorithm> #define maxn 200010 using namespace std; <<; int n,k; int a[maxn]; bool vis[max…
http://codeforces.com/contest/358/problem/C 将最大的放在stack里面,第二大的放在queue中,第三大的放在deck里面.然后模拟就可以了. #include <cstdio> #include <cstring> #include <queue> #include <algorithm> using namespace std; ]; priority_queue<int ,vector<int&g…
http://codeforces.com/contest/358/problem/B 先按照题意说的构造一个字符串s,然后与对比的字符串T比较,看看在字符串T中顺序查找有没有字符串S的所有字符,有输出yes,否则输出no. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ],s[]; int n; int main() { while(scanf("…
题目大意:给一棵树,求树上两点之间距离为K的点对数目. 方程含义: dp(i,j)表示从已经遍历过的点到当前点i,路径长度为 j 的路径条数.因此,对于当前点,每当遍历了其中一个儿子节点的时候,首先统计当前情况下的结果,然后要更新dp(i, j) 初始条件dp(i,0)= 1 #include <cstdio> #include <cstring> #include <vector> using namespace std; #define N 50005 vector…
题意: 一棵树,询问一个子树内出现次数$≥k$的颜色有几种 强制在线见上一道 用莫队不知道比分块高到哪里去了,超好写不用调7倍速度!!! 可以用分块维护出现次数这个权值,实现$O(1)-O(\sqrt{N})$修改查询 [update 2017-03-22]还可以用dsu on tree做,并不想再写了... #include <iostream> #include <cstdio> #include <algorithm> #include <cstring&g…
<题目链接> 题目大意: 在一个水果篮里有n种水果,并且这些水果每一种都有一个美味度和一个卡路里的属性, 小明要从这些水果中选出来一些做一个水果沙拉, 并且要求他的水果沙拉的美味度是卡路里的k倍,问小明是否可以做出这么一个水果沙拉,若不能输出-1,否则输出复合要求的最大的美味值. 解题思路: 题目的限制条件为物品的价值总和与卡路里的比值要为K,这个控制,于是我们将卡路里总和乘到的右边,然后移项,可得(a1-k*b1)+(a2-k*b2)+……+(an-k*bn)=0.因此就将 (ai-k*bi…
题目:http://codeforces.com/problemset/problem/366/E 事实上就是找 n * m 矩阵中数字 x 和 数字 y 的最远距离. 方法參照武森的论文<浅谈信息学中的"0"和"1"> 先约定符号:xi,xj  (i,j)是x的下标,当然.矩阵中的值是能够反复的 上面是武森的论文原文.加上我之前的符号约定,我在做点解释: 事实上那个max={四种可能}  更好的写法是: |xi-yi|+|xj-yj|=max((1),…
http://codeforces.com/problemset/problem/272/E 把仇恨关系想象为边, 因为度只能为0,1,2,3,所以有以下几种 0,1 直接放即可 2: 有(1,1),(0,2)两种情况,第一种随便放,第二种放0那里 3:有(1,2),(0,3)两种情况,第一种放1,第二种放0那里 也就是说,怎样都有解 dfs寻找即可 不过一开始觉得这样不靠谱,因为时间复杂度很高,不过没想到过了 #include <cstdio> #include <vector>…
Polycarp has n coins, the value of the i-th coin is ai. It is guaranteed that all the values are integer powers of 2 (i.e. ai=2d for some non-negative integer number d). Polycarp wants to know answers on q queries. The j-th query is described as inte…