链接 https://codeforces.com/contest/1282/problem/B2 题意: 商店买东西,商店有n个物品,每个物品有自己的价格,商店有个优惠活动,当你买恰好k个东西时可以只为其中最贵的那个付款,求有限的钱中买到的最多的物品数量,你可以多次使用优惠. 思路:把所有商品的价格排序从小到大一遍,设第i个物品的价格是a[i],Sum[i]表示购买前i个物品花费的钱,作为前缀和.可以发现当你买了当第i个物品时,那么只需要支付Sum[i-k] + a [i] 即可,因为你买了当…
原题链接:http://codeforces.com/contest/1282/problem/B2题目大意:刚开始有 p 块钱,商店有 n 件物品,你每次可以只买一件付那一件的钱,也可以买 k 件只付最贵那件的钱,问你最多能买几件 (k<=n<=2e5) 首先我们要明确,如果你买了这一件商品,那么你一定买了比这件商品价格低的所有商品,因为这样买花的钱才会更少,方法才是最优的. 解法一:这道题用 背包dp 解应该是最直观的,先排序一下,状态要么由前一件转移过来,要么由前 k 件转移过来,即 d…
题意:给你一组数\(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[…
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…
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个数的…
题意:给你两个串s,p,问你把s分开顺序不变,能不能用最多k段合成p. 题解:dp[i][j]表示s到了前i项,用了j段的最多能合成p的前缀是哪里,那么转移就是两种,\(dp[i+1][j]=dp[i][j],dp[i+lcp][j+1]=dp[i][j]+lcp\),这里的lcp是dp[i][j]和i的lcp,然后sa预处理一下st表就行了 //#pragma GCC optimize(2) //#pragma GCC optimize(3) //#pragma GCC optimize(4)…
题目 传送门:QWQ 分析 求结尾0的数量QwQ. 10只能是$ 2 \times 5 $,我们预处理出每个数因子中2和5的数量. 我们接着dp出从左上到右下的经过的最少的2的数量和最少的5的数量.两者取min后就是答案. 特判数据中有0的情况,把他当做10处理.如果此时答案大于1,那么把答案更新成1.因为0只有1个0. 输出也有些小技巧 代码 #include <bits/stdc++.h> using namespace std; ; ], dp[maxn][maxn][]; void p…
传送门 D. The Maths Lecture time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher…
Special Offer! Super Price 999 Bourles! Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 219B Description Polycarpus is an amateur businessman. Recently he was surprised to find out that…
传送:http://codeforces.com/gym/102152/problem/K 题意:给定$n(n\le10^5)$个数$a_i(a_i\le10^9)$,对于任一个子数组中的数进行或操作,问所有的值有多少种? 分析: 假设现在想要求解区间$[1,i]$内的答案,那么需要先处理出$[1,i-1],[2,i-1],[3,i-1]......[i-1,i-1]$.然后将这些答案暴力与$a_i$取$|$. 代码: #include<bits/stdc++.h> using namespa…
题目链接:http://codeforces.com/contest/1133/problem/E 题目大意: 在n个人中找到k个队伍.每个队伍必须满足最大值减最小值不超过5.求满足条件k个队伍人数的总和的最大值. 这个题写DP很多的人应该可以很快写出来吧,毕竟不是很难. 思路: 反正最多n^2种状态.用数组存就好了. 先排序. 对于每个点,dp[a][b].表示a到n区间里分b个队伍的答案. 如果a是答案dp[a][b]所需要的,那么我们从a开始到a+i暴力一下(此时,x[a+i]-x[a]>…
传送门 C. Second price auction time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be sho…
题目链接:https://codeforces.com/contest/1133/problem/C 题意: 给出 $n$ 个数,选取其中若干个数分别组成 $k$ 组,要求每组内最大值与最小值的差值不超过5,求 $k$ 组合起来最多可以放多少个数. 题解: 将 $a[1 \sim n]$ 从小到大排序,排序后每个组必定可以视为数组 $a$ 上一段连续区间, $f[i][j]$ 表示到第 $i$ 个数为止,前面组成 $j$ 组,最多可以包含多少个数. 那么,考虑第 $i$ 个数选取与否,如果不选,…
链接:https://codeforces.com/contest/1269/problem/E 题意:给一个序列P1,P2,P3,P4....Pi,每次可以交换两个相邻的元素,执行最小次数的交换移动,使得最后存在一个子段1,2,…,k,这是题目所定义的f(k),题目要求求出所有的f(n),并依次输出. 思路:首先考虑逆序对问题,比如3 2 1 4这个序列,要使其变为1 2 3 4,最小的移动次数是这个序列中逆序对之和,2+1 = 3,逆序对是(3,2) (3,1)(2,1),但是在比如序列3…
题目: You are a coach at your local university. There are nn students under your supervision, the programming skill of the ii-th student is aiai. You have to form kk teams for yet another new programming competition. As you know, the more students are…
K. Malek and Summer Semester   time limit per test 1.0 s memory limit per test 256 MB input standard input output standard output Malek registered n courses for the summer semester. Malek has a success rate m, which means he has to succeed at least i…
A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_back using namespace std; typedef long long ll; typedef unsigned long long ull; ][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }}; ; + + + + 1e9…
这个题就是从字符串中删除一个字符,然后剩下的是回文串. 我写的代码虽然长得好看,但是循环里面的比较条件容易想错,太智障了... 一开始写的是计数比较,但是有的时候下标相同的也比较了,为了简单一些,直接看有没有条件不成立的,这样就少想好多东西(偷懒为主,嘻嘻嘻). 代码: #include<cstdio> #include<cstring> #include<iostream> #include<cmath> #include<algorithm>…
C. Longest Regular Bracket Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/5/C Description This is yet another problem dealing with regular bracket sequences. We should remind you that a bracket sequence…
题目链接: http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test2 secondsmemory limit per test256 megabytes 问题描述 There are b blocks of digits. Each one consisting of the same n digits, which are given to you in the inp…
C. Gerald and Giant Chess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/problem/C Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . The…
http://codeforces.com/contest/754/problem/C C. Vladik and chat time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Recently Vladik discovered a new entertainment — coding bots for social netwo…
D. Bad Luck Island Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/problem/D Description The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random i…
任意门:http://codeforces.com/contest/1114/problem/D D. Flood Fill time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a line of nn colored squares in a row, numbered from 11 to nn f…
Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is an executive boarding manager in Byteland airport. His job is to optimize the boarding process. The planes in Byteland have s rows, numbered from 1 t…
D. Brand New Problem 题目连接: http://www.codeforces.com/contest/201/problem/D Description A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make a…
C. Karen and Supermarket     On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to b dollars.…
Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the follow…
http://codeforces.com/group/1EzrFFyOc0/contest/711/problem/C https://blog.csdn.net/qq_36368339/article/details/78568585?locationNum=6&fps=1  题解 题意:(真难理解)有n个点,m种颜色,你要给n个点上没有颜色的点染色.每个点i对应染的颜色j有一个颜料消耗,p[i][j]是点i染成j颜色的花费,你必须保证有k段颜色的点,输出最少花费多少颜料. 思路:题意稍微不…
链接: https://codeforces.com/contest/1228/problem/E 题意: You have n×n square grid and an integer k. Put an integer in each cell while satisfying the conditions below. All numbers in the grid should be between 1 and k inclusive. Minimum number of the i-t…