题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考虑:如果操作的次数最少,那么最终得到的不降的数列,必然是由原始数列中的数组成的,具体的证明可以使用反证法 知道了上面讲述的性质,这题就好搞了 先将原始数列(设为 A,共 n 个数)中所有的数去重并从小到达排序,保存在另一个数列中(设为 B,共 m 个数) 定义状态:f[i][j] 表示将原始数列中的…
题目链接: http://www.codeforces.com/contest/10/problem/D D. LCIS time limit per test:1 secondmemory limit per test:256 megabytes 问题描述 This problem differs from one which was on the online contest. The sequence a1, a2, ..., an is called increasing, if ai …
D. LCIS 题目连接: http://www.codeforces.com/contest/10/problem/D Description This problem differs from one which was on the online contest. The sequence a1, a2, ..., an is called increasing, if ai < ai + 1 for i < n. The sequence s1, s2, ..., sk is call…
C. Digital Root 题目连接: http://www.codeforces.com/contest/10/problem/C Description Not long ago Billy came across such a problem, where there were given three natural numbers A, B and C from the range [1, N], and it was asked to check whether the equat…
B. Cinema Cashier 题目连接: http://www.codeforces.com/contest/10/problem/B Description All cinema halls in Berland are rectangles with K rows of K seats each, and K is an odd number. Rows and seats are numbered from 1 to K. For safety reasons people, who…
A. Power Consumption Calculation 题目连接: http://www.codeforces.com/contest/10/problem/A Description Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minute…
D. LCIS time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output This problem differs from one which was on the online contest. The sequence a1, a2, ..., an is called increasing, if ai < ai + 1 for …
C. Balance time limit per test 3 seconds memory limit per test 128 megabytes input standard input output standard output Nick likes strings very much, he likes to rotate them, sort them, rearrange characters within a string... Once he wrote a random…
Codeforces79C 题意: 求s串的最大子串不包含任意b串: 思路: dp[i]为以i为起点的子串的最长延长距离. 我们可以想到一种情况就是这个 i 是某个子串的起点,子串的长度-1就是最短, 或者这个 前面的长度 +这个i 就是答案. 所以预处理一下,以 i 为起点的最短子串距离就好了,这里利用KMP比较方便. #include <bits/stdc++.h> using namespace std; typedef long long LL; const int INF=0x3f3…
写份DIV2的完整题解 A 判断下HQ9有没有出现过 #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> #include<vector> #include<cmath> #include<queue> #include<set> using namespace s…