Codeforces 706 C. Hard problem (dp)】的更多相关文章

题目链接:http://codeforces.com/problemset/problem/706/C 给你n个字符串,可以反转任意一个字符串,反转每个字符串都有其对应的花费ci. 经过操作后是否能满足字符串str[i]>=str[i-1],能就输出最小花费,不能输出-1. dp[i][0] 表示不反转i的最小花费(str[i] >= str[i - 1] || str[i] >= reverse(str[i - 1])) dp[i][1] 则表示反转i的最小花费... 初始dp[1][…
题目链接: C. Hard problem time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help.…
题目链接:http://codeforces.com/contest/713/problem/C 题解:这题也算是挺经典的题目了,这里附上3种解法优化程度层层递进,还有这里a[i]-i<=a[i+1]-(i+1),处理一下. 首先是最基础的dp[i][j]前i位最大值为j的最小值为多少. #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include…
题目链接:http://codeforces.com/contest/721/problem/C 题意:从1走到n,问在时间T内最多经过多少个点,按路径顺序输出. 思路:比赛的时候只想到拓排然后就不知道怎么办了......先拓扑排序,再按照拓扑的顺序进行DP,dp[to][j](到i点走过j个点最短时间) = min(dp[to][j], dp[i][j] + dis) #include<bits/stdc++.h> using namespace std; typedef long long…
题目链接:http://codeforces.com/contest/543/problem/D 给你一棵树,初始所有的边都是坏的,要你修复若干边.指定一个root,所有的点到root最多只有一个坏边.以每个点为root,问分别有多少种方案数. dp[i]表示以i为子树的root的情况数,不考虑父节点,考虑子节点.   dp[i] = dp[i] * (dp[i->son] + 1) up[i]表示以i为子树的root的情况数(倒着的),考虑父节点,不考虑子节点.  这里需要逆元. 注意(a/b…
题目链接:http://codeforces.com/contest/467/problem/C 求k个不重叠长m的连续子序列的最大和. dp[i][j]表示第i个数的位置个序列的最大和. 前缀和一下就好了.空间可以优化,滚动数组就好了. //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cs…
A. Substring and Subsequence 题目连接: http://codeforces.com/contest/163/problem/A Description One day Polycarpus got hold of two non-empty strings s and t, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately w…
D. The Bakery time limit per test:2.5 seconds memory limit per test:256 megabytes input:standard input output:standard output Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven whic…
题目链接: http://codeforces.com/contest/1154/problem/F 题意: 有$n$个物品,$m$条优惠 每个优惠的格式是,买$x_i$个物品,最便宜的$y_i$个物品免费 每条优惠可以无限次使用(当时以为每个优惠只能用一次) 可以买一个物品,不参与优惠 求买k个物品的最低花费 数据范围: $1 \le n, m \le 2 \cdot 10^5, 1 \le k \le min(n, 2000)$$1 \le a_i \le 2 \cdot 10^5$$1 \…
题目链接:https://codeforces.com/contest/1155/problem/D 题意:给定n个数,可以选择一段连续子段将其乘x,也可以不操作,求最大连续子段和. 思路:比赛时觉得是dp,但怎么也想不出来QAQ,dp太难了...赛后看了别人题解,找到状态和转移方程就很简单了,然而比赛时我就是想不到... 考虑下标i:有3种情况,可能[0,i]都没有乘x,可能i乘了x,可能[i,n]都不会乘x.分别用dp[i][0]表示以i结尾的最长子段和且 [0,i]都没乘x,dp[i][1…