[CodeForce]358D Dima and Hares】的更多相关文章

有N<3000只宠物要喂,每次只能喂一只,每喂一只宠物,宠物的满足度取决于: 1 紧靠的两个邻居都没喂,a[i] 2 邻居中有一个喂过了,b[i] 3 两个邻居都喂过了,c[i] 把所有宠物喂一遍,得到的满足度之和最大为多少. =========== 动态规划, 动态转移方程的难点 在于 搞清楚“无后效性” =========== dp[i]为从i开始往后喂 以第一只宠物为例,可以选择 1) 先喂第一只, a[1] + 第二只排在第一只后面的最大值.注意,先喂第一只,只会影响第二只. 2)先喂第…
题目链接: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分别表示周围没有…
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个…
题目链接: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]的右边视为永远有一个取不走的物品. 问你最大收益是多少. 题解: 表示状…
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…
E. Dima and Horses Dima came to the horse land. There are n horses living in the land. Each horse in the horse land has several enemies (enmity is a symmetric relationship). The horse land isn't very hostile, so the number of enemies of each horse is…
B. Dima and Sequence Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence: f(0) = 0; f(2·x) = f(x); f(2·x + 1)…
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…
从本质入手,这个东西影响取值的就是相邻两个哪个先取 设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…
状态的定义挺奇特的~ 发现最终每一个物品一定都会被选走. 令 $f[i][0/1]$ 表示 $a[i]$ 在 $a[i-1]$ 前/后选时 $1$~$(i-1)$ 的最优解. 因为一个数字的价值只由其相邻两边决定~ code: #include <bits/stdc++.h> #define N 3007 #define ll long long #define setIO(s) freopen(s".in","r",stdin) using names…
A - Dima and Continuous Line 水题:直接模拟: #include<cstdio> #define maxn 1005 using namespace std; int x[maxn],y[maxn]; int main() { int n,a,b,last; scanf("%d",&n); ; ;i<n;i++) { scanf("%d",&b); a=last; last=b; )continue; i…
CF1252J Tiling Terrace 洛谷评测传送门 题目描述 Talia has just bought an abandoned house in the outskirt of Jakarta. The house has a nice and long yard which can be represented as a one-dimensional grid containing 1 \times N1×N cells. To beautify the house, Tali…
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following proble…
Codeforces Round #262 (Div. 2) B B - Little Dima and Equation B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot a…
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is a lamp in a block, it will light it’s block and the direct adjacent blocks. For example, if there is a lamp at block 3, it will light the blocks 2, 3…
题目链接: http://codeforces.com/problemset/problem/272/D D. Dima and Two Sequences time limit per test2 secondsmemory limit per test256 megabytes 问题描述 Little Dima has two sequences of points with integer coordinates: sequence (a1, 1), (a2, 2), ..., (an, …
e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头一小改就过了! 只能呵呵...C题还是看了下,又没写,也许写不出吧...的确时候还是看了别人的额,自己写只到第8组WA! 希望下次少,一点! 哎,等我不,b了这个世界也许都不同了!…
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all…
D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/problem/D Description Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them…
http://codeforces.com/contest/374/problem/C 记忆化搜索,题意:求按照要求可以记过名字多少次,如果次数为无穷大,输出Poor Inna!,如果不经过一次输出Poor Dima!,否则输出输出次数. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 1001 #define LL __int64 using namespace std; ;…
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…
Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to ha…
C. Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to…
Sereja and Dima time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a n…
又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数(n<=200). 首先很明显可能是区间dp,我们可以记f[i][j]为从i到j的这个多边形的三角剖分数,那么f[i][j]=f[i][k]*f[j][k]*(i,j,k是否为1个合格的三角形) Code: #include<cstdio> #include<iostream> #…
codeforce 375_2 标签: 水题 好久没有打代码,竟然一场比赛两次卡在边界条件上....跪 b.题意很简单...纯模拟就可以了,开始忘记了当字符串结束的时候也要更新两个值,所以就错了 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N = 300; char a[N]; int main() { int n; int l; int su…
codeforce 367dev2_c dp 标签: dp 题意: 你可以通过反转任意字符串,使得所给的所有字符串排列顺序为字典序,每次反转都有一定的代价,问你最小的代价 题解:水水的dp...仔细想想就有了,一个位置要么反转要么就不反转...保证在满足条件时候转移 扔个代码: #include<cstdio> #include<cstring> #include<string> #include<iostream> #include<algorith…
三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃料涂,将相邻相同颜色的树划为一组,最后使得组数为k,并且所用燃料的量最小,给出了每棵树涂j种燃料的用量,如果存在这种涂法输出最小用量,不存在输出-1: 题解: 很容易看出是一个三维dp, dp[i][j][k] 表示处理到第i棵树,最后一棵树为颜色j,现在已经分成的组数为k的时候的最小用量 转移方程如果当前…
强连通分量 标签: 图论 算法介绍 还记得割点割边算法吗.回顾一下,tarjan算法,dfs过程中记录当前点的时间戳,并通过它的子节点的low值更新它的low,low值是这个点不通过它的父亲节点最远可以到达的dfn值最小的点,如果当前的节点的low>他父亲节点的dfn说明它不能通过其他的边到达它的父亲,那么它和他父亲的这条边就是割边,在这个算法中有三个标号,VIS数组,标记为0表示没有被访问到,标记为1表示这个点正在搜索它的自孩子,标记为2表示这个点已经处理过了,就是已经找到了它属于哪个联通块,…