传送门 容易想到 $dp$,但是如果直接设 $f[i][j]$ 表示修正完前 $i$ 个位置,第 $i$ 个位置增加了 $j$ 高度显然是不行的 考虑有性质,发现每个位置只会被左右两个位置影响而改变,即如果一边等于它那么才要考虑增加它的位置,并且如果此时另一边恰好比它原本高度大 $1$,这个位置才要再考虑增加高度 所以容易发现,每个位置最多增加 $2$ 的高度,然后就可以直接 $dp$ 了 #include<iostream> #include<cstdio> #include&l…
1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1-9每个字母分别要ai升油漆,问最多可画多大的数字. 贪心,也有点考思维. #include<bits/stdc++.h> using namespace std; #define LL long long #define INF 0x3f3f3f3f int main() { ]; while(…
题目链接:Codeforces 484E Sign on Fence 题目大意:给定给一个序列,每一个位置有一个值,表示高度,如今有若干查询,每次查询l,r,w,表示在区间l,r中, 连续最长长度大于w的最大高度为多少. 解题思路:可持久化线段树维护区间合并,前端时间碰到一题可持久化字典树,就去查了一下相关论文,大概知道了是 什么东西. 将高度依照从大到小的顺序排序,然后每次插入一个位置,线段树维护最长连续区间,由于插入是依照从大到小的顺 序,所以每次的线段树中的连续最大长度都是满足高度大于等于…
题目链接:http://codeforces.com/problemset/problem/349/B 题目意思:给定v升的颜料和9个需要花费ad 升的颜料,花费ad 升的颜料意味着得到第d个数字,现在要求在所有的花费不超过v升的情况下,使得这些数字组合起来是最大的. 一开始直接从最小花费的颜料着手,如果花费的颜料是相同的,就转到从d(也就是位数)最大贪心.这样测试9就开始卡住了. 受到乌冬兄的指点迷津,终于有了思路,陆陆续续改了很多次,终于过了.以下摘自他的语录,白话文,大家请谅解: 稳用颜料…
题目链接:http://codeforces.com/problemset/problem/349/B 题目大意 小明要从9个数字(1,2,--,9)去除一些数字拼接成一个数字,是的这个数字最大. 但是小明每取一个数字i就会消耗a[i]点体力,小明目前总共有v点体力. 举个例子: 小明如果有5点体力,而a[1]到a[9]的数值依次为: 5 4 3 2 1 2 3 4 5 那么最好的办法就是取5次数字5,因为a[5]=1最小,所以最终得到的数字是11111,比起其他的取数策略所得到的数字都要大.…
题目链接:https://codeforces.com/contest/1132/problem/C 题意: 栅栏有 $n$ 个节,有 $q$ 个人可以雇佣来涂栅栏,第 $i$ 个人可以涂第 $l_i$ 节到第 $r_i$ 节. 但是现在预算紧张,所以只能雇佣 $q-2$ 个人,你想确认雇佣哪 $q-2$ 个人使得涂色栅栏的节数最大. 题解: 首先看到 $n$ 的范围,就可以想到大概可以枚举第一个不雇佣的人再枚举第二个不雇佣的人,时间复杂度在 $O(n^2)$ 左右. 先假定第一个不雇佣的人是第…
349B - Color the Fence 贪心 代码: #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<cstring> using namespace std; ; const int INF=0x7f7f7f7f; ]; int main() { int n; int MIN=INF; ; cin>>n; ;i&l…
递归.分治. . . C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his ol…
题目描述: D. Color the Fence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to…
C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his…
题意:给出1~9数字对应的费用以及一定的费用,让你输出所选的数字所能组合出的最大的数值. 析:DP,和01背包差不多的,dp[i] 表示费用最大为 i 时,最多多少位,然后再用两个数组,一个记录路径,一个记录是数字几即可. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib>…
http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护最长连续子区间 把数从大到小插入主席树 对于每个询问,二分x 在第x棵线段树中查,若最长连续子区间>=w,到代表更大的线段树中查 没有建第n+1棵线段树,导致前面节点的siz不对,WA了一次 #include<cstdio> #include<iostream> #include…
A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the frien…
G. Fence Divercity 题目连接: http://www.codeforces.com/contest/659/problem/G Description Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecutively fastened vertical boards of centimeter widt…
题目链接:http://codeforces.com/problemset/problem/448/C C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Bizon the Champion isn't just attentive, he also is very hardworking. B…
Fence Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 363B64-bit integer IO format: %I64d      Java class name: (Any) There is a fence in front of Polycarpus's home. The fence consists of n planks of…
链接: https://codeforces.com/contest/1221/problem/D 题意: You have a fence consisting of n vertical boards. The width of each board is 1. The height of the i-th board is ai. You think that the fence is great if there is no pair of adjacent boards having…
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/y990041769/article/details/37935237 题目:codeforces 448CPainting Fence 题意:n个1* a [ i ] 的木板.把他们立起来,变成每一个木板宽为1长为 a [ i ] 的栅栏.如今要给栅栏刷漆.刷子宽1,每一刷子能够刷随意长,如今让你求最少须要多少刷子? 分析:题目看似没有头绪.细致分析的话事实上非常简单 首先,我们假如每次都刷一个木…
E. Sign on Fence   Bizon the Champion has recently finished painting his wood fence. The fence consists of a sequence of n panels of 1 meter width and of arbitrary height. The i-th panel's height is hi meters. The adjacent planks follow without a gap…
http://codeforces.com/problemset/problem/659/G 思路: f(i,0/1,0/1) 表示到了第i个,要被切的块开始了没有,结束了没有的状态的方案数 递推看代码: //File Name: cf659G.cpp //Author: long //Mail: 736726758@qq.com //Created Time: 2016年07月12日 星期二 12时40分28秒 #include <stdio.h> #include <string.h…
题目链接:http://codeforces.com/problemset/problem/363/B 题目意思:给定整数n和k,需要从n个数中找出连续的k个数之和最小,输出这连续的k个数中的第一个数的下标. 直接暴力果断TLE,于是想到之前做的那条332B - Maximum Absurdity DP题的做法,决定开多一个额外的数组b[],在输入的时候把a[i]中前i个数的和都记录到b[i]中,这样通过b[i] - b[i-k]即可得出序列h1, h2, ..., hn (1 ≤ hi ≤ 1…
题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In orde…
http://codeforces.com/contest/448/problem/C 题意:给你n宽度为1,高度为ai的木板,然后用刷子刷颜色,可以横着刷.刷着刷,问最少刷多少次可以全部刷上颜色. 思路:dp[i][j] 表示在第i列以后的木板都已刷完且第j列的木板是横着刷的,最少需要的次数.如果a[i]>=a[j]的情况,比较再竖着刷一次和横着刷哪一个情况次数少. #include <cstdio> #include <iostream> #include <cst…
John Doe has a crooked fence, consisting of n rectangular planks, lined up from the left to the right: the plank that goes i-th (1 ≤ i ≤ n)(from left to right) has width 1 and height hi. We will assume that the plank that goes i-th (1 ≤ i ≤ n) (from…
解题报告 给篱笆上色,要求步骤最少,篱笆怎么上色应该懂吧,.,刷子能够在横着和竖着刷,不能跳着刷,,, 假设是竖着刷,应当是篱笆的条数,横着刷的话.就是刷完最短木板的长度,再接着考虑没有刷的木板,,. 递归调用,,. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define inf 999999999999999 using namespace…
C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his…
Description Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in a row. Adjacent planks have no gap b…
https://codeforces.com/contest/1132/problem/C 采用逆向思维,要求最大的覆盖,就先求出总的覆盖,然后减去删除两个人贡献最少的人 #include<iostream> #include<vector> #include<algorithm> using namespace std; vector<]; ][],con1[];//一维数组:这个人的贡献,二维数组:这两个人共同的贡献 int main(){ int n,q;…
Codeforces 1132 C 题意:给一些区间\([l_i,r_i]\),从中删掉两个,求剩下的区间最多能够覆盖的格子数量. 思路:首先枚举第一个删掉的区间,然后我们可以通过差分来求出每个格子被多少个区间覆盖了,随后求出所有格子中被\(1\)个区间覆盖的数量的前缀和,再枚举第二个删掉的区间,找删掉的\(1\)个区间覆盖的最少的即为答案. Codeforces 1132 C 分析 tataky: 首先我们将所有的互不包含的区间们放在\(v\)里,然后看被包含的区间有多少,如果超过2个就直接输…
链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: 思路: 因为查询的到的值一定是输入的其中一个,那么我们可以二分答案,判断二分得到的答案是否符合,那么在这里我们就只需要找到某个数x,查询区间[l,r]有多少个连续的数大于x,这个操作只需要将高度从小到达排序,倒着插入主席树中,值设为1,那么只要维护有多少个连续的1(线段树区间合并的方法),就代表有…