Codeforces 934C - A Twisty Movement】的更多相关文章

934C - A Twisty Movement 思路:dp 很容易想到要预处理出1的前缀和pre[i]和2的后缀和suf[i] 然后枚举区间,对于每个区间如果能求出最长递减序列的长度,那么就能更新答案了 这个用dp求 状态: dp[i][j][0]表示i--j区间以2结尾的最长递减序列长度,很明显这个序列全为2,所以也就是i--j区间2的个数 dp[i][j][1]表示i--j区间以1结尾的最长递减序列长度 状态转移: dp[i][j][0]=dp[i][j-1][0]+(a[j]==2) d…
Description 题库链接 给你一个长度为 \(n\) 的只含有 \(1,2\) 的序列.你可以选择其中的一段 \([l,r]\) ,将区间翻转,翻转后使得单调不下降序列最长.求最长长度. \(1\leq n\leq 2000\) Solution 考虑线段树维护一系列矩阵,分别表示区间内所选的数字由 \(1\rightarrow 1,1\rightarrow 2,2\rightarrow 1,2\rightarrow 2\) 变化的最长不下降序列的长度. 我们枚举翻转区间的左右端点,线段…
思路: 实际上是求原序列中最长的形如1......2......1......2......的子序列的长度.令dp[i][j](1 <= j <= 4)表示在子序列a[1]至a[i]中形如前j部分的子序列的最大长度.可以使用动态规划求解. 实现: #include <bits/stdc++.h> using namespace std; ]; int main() { int n, d; while (cin >> n) { memset(dp, , sizeof dp…
C. A Twisty Movement time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clot…
C. A Twisty Movement time limit per test1 second memory limit per test256 megabytes Problem Description A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods,…
题目意思: 给长度为n(n<=2000)的数字串,数字只能为1或者2,可以将其中一段区间[l,r]翻转,求翻转后的最长非递减子序列长度. 题解:求出1的前缀和,2的后缀和,以及区间[i,j]的最长不递增子序列. f[i][j][0]表示区间i-j以1结尾的最长不递增子序列: f[i][j][1]表示区间i-j以2结尾的最长不递增子序列,显然是区间i-j 2的个数: 所以转移方程为: f[i][j][1] = f[i][j-1][1] + (a[j]==2);   f[i][j][0] = max…
[链接] 我是链接,点我呀:) [题意] [题解] 因为只有1和2. 所以最后肯定是若干个1接着若干个2的情况. 即11...11222...222这样的. 1.首先考虑没有翻转的情况. 那么就直接枚举1和2的边界i在什么地方,即1..i全是1,i+1..n全是2. 只需统计某个范围里面1和2的个数就可以了. 然后取最大值就ok. 2.考虑有翻转的情况. 假设翻转的区间是[i..j] 我们最好先固定j然后让i从j递减到1这样变化. 这样的话我们可以利用[i+1,j]这一段得到的东西继续搞,不用每…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] ans初值值为a[1..n]中1的个数. 接下来考虑以2为结尾的最长上升子序列的个数. 枚举中间点i. 计算1..i-1中1的个数cnt1. 计算i..n中2的个数cnt2. ans = max(ans,cnt1+cnt2) 写个前缀和 翻转. 断点在l..r中 f[l][r]表示l..r翻转后以2结尾的最长上升子序列 简单DP ans = max(ans,cnt[l-1][1]+f[l][r]+cnt[n][2]-cnt[r]…
https://codeforces.com/problemset/problem/933/A 这个是一个dp,但是我并没有看出来,然后也不太会写, 这种题一般应该要想到先预处理前缀和后缀,然后再进行dp dp[i][j][0]----表示从区间 i~j 以2结尾的最长递减序列 dp[i][j][1]----表示从区间 i~j 以1结尾的最长递减序列 为什么这样定义,我很迷,完全不知道要这么写,…
题意 题目链接 Sol 这题最直接的维护区间以0/1结尾的LIS的方法就不说了. 其实我们可以直接考虑翻转以某个位置为中点的区间的最大值 不难发现前缀和后缀产生的贡献都是独立的,可以直接算.维护一下前缀/后缀和即可 #include<bits/stdc++.h> #define Pair pair<int, int> #define MP(x, y) make_pair(x, y) #define fi first #define se second #define LL long…
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represen…
题意翻译 给定一个序列 A,你可以翻转其中的一个区间内的数,求翻转后的序列的最长不下降子序列的长度.(∣A∣≤2000,1≤ai≤2|A|\le 2000,1\le a_i \le 2∣A∣≤2000,1≤ai​≤2 ) 感谢@touristWang 提供的翻译 题目描述 A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips a…
题意 有一个只包含1和2的序列,试翻转一个区间,使得结果中非连续非递减数列最长. 思路 一. 作出1的前缀计数和为cnt1,2的后缀计数和为cnt2, 由于要找出[1,1,1][2,2,2][1,1,1][2,2,2]的四段,设中间的分割点是p,k,q,可得到 ans=cnt1[p]+cnt2[p+1]−cnt2[k+1]+cnt1[q]−cnt1[k]+cnt2[q+1]ans=cnt1[p]+cnt2[p+1]−cnt2[k+1]+cnt1[q]−cnt1[k]+cnt2[q+1] 化简得到…
C. A Twisty Movement   time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and cl…
A A Compatible Pair standard input/output 1 s, 256 MB    x1916 B A Prosperous Lot standard input/output 1 s, 256 MB    x3290 C A Twisty Movement standard input/output 1 s, 256 MB    x527 D A Determined Cleanup standard input/output 1 s, 256 MB    x19…
C. A Twisty Movement time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clot…
Cosmic Tables Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 222B Description The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptiv…
Chamber of Secrets 题目连接: http://codeforces.com/problemset/problem/173/B Description "The Chamber of Secrets has been opened again" - this news has spread all around Hogwarts and some of the students have been petrified due to seeing the basilisk…
B. Ants Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/317/problem/B Description It has been noted that if some ants are put in the junctions of the graphene integer lattice then they will act in the following fashion: eve…
E. Vanya and Field Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/problem/E Description Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the cell with…
C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem/C Description For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed tha…
B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem/B Description A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order…
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem/A Description Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x tha…
B. Strip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/problem/B Description Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right. Now Alexandra wants to split it into some pieces (p…
A. Fight the Monster Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/problem/A Description A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attr…
A. Warrior and Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594/problem/A Description In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this…
C. Edo and Magnets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594/problem/C Description Edo has got a collection of n refrigerator magnets! He decided to buy a refrigerator and hang the magnets on the door. The shop ca…
D. Max and Bike Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/problem/D Description For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cy…
B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/problem/B Description Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of ex…
A. Vitaly and Night Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/problem/A Description One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly de…