题目链接: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…
题目链接: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…
upd on 2021.7.7:修了个 typo Codeforces 题目传送门 & 洛谷题目传送门 首先考虑怎样处理"字典序小"这个问题,按照字典序比大小的套路,我们可以枚举第一位 \(p_x\ne q_x\) 的位置 \(x\),那么必然有 \(p_x<q_x\),为了避免后面计算中出现太多形如 \(n-x\) 之类的东西,我们不枚举 \(x\),instead 我们枚举 \(i=n-x\),那么真正的 \(x\) 等于 \(n\) 减去你枚举的 \(i\). 接下…
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…
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…
E1. String Coloring (easy version) time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output This is an easy version of the problem. The actual problems are different, but the easy version is almost…
C. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a ga…
题意: 取一字符串不相交的前缀和后缀(可为空)构成最长回文串. 思路: 先从两边取对称的前后缀,之后再取余下字符串较长的回文前缀或后缀. #include <bits/stdc++.h> using namespace std; bool ok(const string &s,int l,int r){ while(l<=r&&s[l]==s[r]) ++l,--r; return l>r; } void solve(){ string s;cin>&…
题目链接: E1:http://codeforces.com/contest/1108/problem/E1 E2:http://codeforces.com/contest/1108/problem/E2 题目大意: 给你n个数,然后给你m个区间,每一个区间代表将给定的n个数这个区间内都减去1,每个区间最多使用一次.然后问你使用哪些区间能够使得这n个数中最大数和最小的差值最大? 首先对于E1:这么小的数据不暴力搞啥??直接问枚举就完事了,每一次枚举的时候保持一个数不变,假设当前的数是最大的,然…
题目:https://vjudge.net/contest/325352#problem/C 题意:输入n,m,给你一个长度为n的串,然后你有一个集合,集合里面都是你的子序列,集合里面不能重复,集合中元素的花费是 n-当前元素长度 ,也就是删除了几个字符,然后要你求前m个最小花费是多少 思路:我们考虑dp,dp[i][j] 前i个字符删除j个字符的方案数,我们先假设没有重复字符,没有的话,很明显转移方程就是dp[i][j]=dp[i-1][j-1]+dp[i-1][j] 也就是考虑   当前字符…