G - Pictures with Kittens (easy version) dp】的更多相关文章

https://codeforces.com/problemset/problem/1077/F1 这个其实是一个比较简单的dp了 题目大意: 给你n个数,让你从n个数里选出x个数,并且每隔k个至少选一个数. 开始不知道怎么去写,也不知道怎么去定义dp 这个应该是对于dp不是特别的熟练,实际上dp用途很广,而且可以用到的地方很多,效果也很好. 这种时候就应该大胆一点,你需要什么,想达成什么效果那就去这样定义. 这个题目,我们希望dp可以帮我们解决前面n个数,选了x个数的最大和,而且这个还必须每隔…
题目链接:Pictures with Kittens (easy version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:$dp[i][j]$:以i为结尾选择j个数字的最大和. $dp[i][j]=max(dp[i][j],dp[s][j-1]+a[i])$,$s为区间[i-k,i)$. 以i为结尾的最大和可以由i之前k个位置中的其中一个位置选择j-1个,再加上当前位置的ai得到. #include <cstdio> #includ…
F1. Pictures with Kittens (easy version) 题目链接:https://codeforces.com/contest/1077/problem/F1 题意: 给出n个数,以及k,x,k即长度为k的区间至少选一个,x的意思是一共要选x个,少一个或者多一个都不行. 选一个会得到一定的奖励,问在满足条件的前提下,最多得到多少的奖励. 题解: 简单版本数据量比较小,考虑比较暴力的动态规划. dp[i,j]表示前i个数,要选第i个数,目前选了j个所得到的最大奖励,那么当…
题意:给你一组数\(a\),构造一个它的子序列\(b\),然后再求\(b_1-b2+b3-b4...\),问构造后的结果最大是多少. 题解:线性DP.我们用\(dp1[i]\)来表示在\(i\)位置,并且此时子序列的长度是奇数的情况,而\(dp2\)则是偶数情况,对于每个\(a_i\),\(dp[i]\)都可以选它或者不选,拿\(dp1[i]\)举例,如果选择\(a_i\),那么状态则可以从子序列中上一个位置转移过来,所以\(dp1[i]=dp2[i-1]+a[i]\),如果不选就是\(dp1[…
题目链接:Pictures with Kittens (hard version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:数据量5000,O(n^3)的DP不适用.需要加个单调队列优化. 注意每次是从$[i-k,i)$区间,选择加上ai.每次清空双向队列. #include <queue> #include <cstdio> #include <cstring> #include <iostream&g…
Codeforce 1420 C1. Pokémon Army (easy version) 解析(DP) 今天我們來看看CF1420C1 題目連結 題目 對於一個數列\(a\),選若干個數字,求alternating-series的最大值. 前言 C2真的想不到 @copyright petjelinux 版權所有 觀看更多正版原始文章請至petjelinux的blog 想法 \(dp[i][0]\)代表:考慮到第i個數字為止,最後一個數字是負的的最大值 \(dp[i][1]\)代表:考慮到第…
F2 - Pictures with Kittens (hard version) 思路: 单调队列优化dp 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define LL long…
1114 ModricWang's FFT EASY VERSION 思路 利用FFT做大整数乘法,实际上是把大整数变成多项式,然后做多项式乘法. 例如,对于\(1234\),改写成\(f(x)=1*x^3+2*x^2+3*x+4\),那么\(x=10\)处的值就是原数.类似的,对于输入的两个大整数,转换为\(f(x)\) 和\(g(x)\) ,利用FFT求出\(h(x)=f(x)*g(x)\) ,此时\(h(10)\) 就是乘积. 代码 #include <cstdio> #include…
06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land…
06-图2 Saving James Bond - Easy Version(25 分) This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land…
D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output The only difference between easy and hard versions is the size of the input. You are given a string s consistin…
D1. Kirk and a Binary String (easy version) 01串找最长不降子序列 给定字符串s,要求生成一个等长字符串t,使得任意l到r位置的最长不降子序列长度一致 从后往前暴力枚举,枚举每个一替换成0后是否改变了l到r位置的最长不降子序列长度 01串的最长不降子序列,可以通过线性dp求解 dp i表示以i结尾的最长不降子序列长度 dp[0]=dp[0]+s[i]=='0'; dp[1]=max(dp[0],dp[1])+s[i]=='1'; #include<bi…
题目链接:http://codeforces.com/contest/1204/problem/D2 题目是给定一个01字符串,让你尽可能多地改变1变为0,但是要保证新的字符串,对任意的L,R使得Sl,Sl+1,Sl+2...Sr的最长不递减子序列长度保持不变,求新的串s. dp思路,从前往后遍历串s. 1 . 遇到s[ i ] = 0 是不能改变的,因为从i到n的最长不递减子序列必定是以s[ i ] = 0为起点的,改变之后会减少长度. 2 . 遇到s[ i ] = 1.我们考虑如果变为0,首…
B. Ping-Pong (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to in…
3868 - Earthstone: Easy Version Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3867 Description Earthstone is a famous online card game created by Lizard Entertainment. It is a collectible card g…
Problem UVA12569-Planning mobile robot on Tree (EASY Version) Accept:138  Submit:686 Time Limit: 3000 mSec  Problem Description  Input The first line contains the number of test cases T (T ≤ 340). Each test case begins with four integers n, m, s, t (…
Coffee and Coursework (Easy version) time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The only difference between easy and hard versions is the constraints. Polycarp has to write a coursewor…
任意门:http://codeforces.com/contest/1118/problem/F1 F1. Tree Cutting (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an undirected tree of nn vertices. Some vert…
任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The only difference between easy and hard versions…
05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was capture…
Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1460    Accepted Submission(s): 557 Problem Description A Bear tree is a binary tree with such properties : each node has a value o…
Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1487    Accepted Submission(s): 567 Problem Description A Bear tree is a binary tree with such properties : each node has a value o…
D1.Remove the Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output The only difference between easy and hard versions is the length of the string. You are given a string…
B1. Character Swap (Easy Version) This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems. After struggling and failing many times, Ujan decided to tr…
CF1225B1 TV Subscriptions (Easy Version) 洛谷评测传送门 题目描述 The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the kk TV shows. You know the schedule for the next nn days: a seque…
G1 - Into Blocks (easy version) 参考:Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2) G1. Into Blocks (easy version) 思路:先把数据预处理一遍,找到每一种数的最右端的位置,和每一种数的出现的次数,然后,从第一个数字开始遍历,用r保存当前这一块的最大右端,用MAX…
http://codeforces.com/problemset/problem/1216/E1 E1. Numerical Sequence (easy version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The only difference between the easy and the hard ver…
Codeforces Round #620 F2. Animal Observation (hard version) (dp + 线段树) 题目链接 题意 给定一个nm的矩阵,每行取2k的矩阵,求总共矩阵里的数的和最大值,重复取到的数不算 题解 dp[i]表示当前行从第i个数开始取矩阵的最大值 dp[i] = 上一行中最大数 + 当前行第i个数到第i+k-1个数的和 - 当前行重复的 + 下一行第i个数到第i+k-1个数的和 用线段树维护 上一行中最大数 + 当前行第i个数到第i+k-1个数的…
题目链接: C1. Skyscrapers (easy version) 题目描述: 有一行数,使得整个序列满足 先递增在递减(或者只递增,或者只递减) ,每个位置上的数可以改变,但是最大不能超过原来的值. 最后找到满足这样的序列并且满足 这种方案 所有数加起来 和 是最大的. 考察点 : 贪心,对数据范围的掌握程度,计算每次加数时有可能会 爆 int 析题得侃: 比赛的时候看到这道题直接找了 最大值,然后以最大值为中心向两侧递减,交了一发, WA 后来想到可能会有重复的最大值,因为每个值并不是…
D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) ) 题意 给出一个串 给出删除每一个字符的代价问使得串里面没有hard的子序列需要付出的最小代价(子序列不连续也行) 思路 要满足hard 先要满足har 要满足har 先要满足ha 一次类推 这类问题的一个共同点是要每个地方都要满足一系列前置条件才能成立也就是说有衔接关系 所以如果是构造问题 那么dp数组加一维已经满足了几个,如果是删除问题dp数组加一维 切断了哪一个即可 所以我们可以设置dp数学 dp[i][1,2,3…