codeforces 1183H 动态规划】的更多相关文章

codeforces 1183H 动态规划 传送门:https://codeforces.com/contest/1183/problem/H 题意: 给你一串长度为n的字符串,你需要寻找出他的最长的前k个子串,问你得到这些子串需要减少的字符个数之和是多少,easy版本的k是100,hard版本的k是1e12. 题解: hard版本题解: dp[i][j]表示前i个字符中选择了j个的子串数目 如果前面有出现过的字符呢?比如 aba 算到第二个a的时候 把ab 删掉 和 把 ba删掉 得到同一种结…
Codeforces 837D 动态规划 传送门:https://codeforces.com/contest/837/problem/D 题意: 给你n个数,问你从这n个数中取出k个数,这k个数的乘积的末尾最多有多少个0 题解: 要想让乘积的末尾有0,实际上就是2的倍数和5的倍数相乘才能得到贡献,所以每个数对答案的贡献实际上就是这个数中包含的2的个数还有这个数中包含的5的数对答案的贡献 设定dp状态为 \(dp[i][j]表示从n个数中选出i个数,其中有j个5的个数,最多有多少个2\) 边界…
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working…
http://codeforces.com/problemset/problem/429/B 可以参考这篇文章: http://blog.csdn.net/pure_lady/article/details/46764839 因为有断点,所以可以预处理四个顶点到任意点的距离最大值,通过拼接得到断点后的距离 然后就是枚举断点的情况,发现断点不可能在边缘,就可以开始写了 #include <iostream> #include <string> #include <cstring…
题目链接: http://codeforces.com/contest/1183/problem/H 题意: 给出一个长度为$n$的字符串,得到$k$个子串,子串$s$的花费是$n-|s|$ 计算最小花费 数据范围: $1 \le n \le 100, 1 \le k \le 10^{12}$ 分析: dp依然还是那么神奇 定义$dp[i][j]$为考虑前$i$个字符,删除$j$个字符的方案数 首先$dp[i][j]=dp[i-1][j]+dp[i-1][j-1]$ 前者为不保留第$i$个字符,…
这道题目昨晚比赛没做出来,昨晚隐约觉得就是个动态规划,但是没想到怎么DP,今天想了一下,突然有个点子,即局部最优子结构为 1-j,j<i,遍历i,每次从所有的1到j当中的最优解里面与当前商品进行匹配,若匹配成功,遍判断是否要加....结果WA了,想了一下,确实不对,因为题目的限制条件是所有美味值的总和除以所有卡路里总和一定要==k,这个就好麻烦了,根本不是我定义的那种子结构最优即可,任意后面的状态都可影响前面,所以规划方向无法确定...其实这个时候就应该想到用背包问题,背包也是商品挑选,但规划方…
A. Chain Reaction time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. Wh…
题目: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] 也就是考虑   当前字符…
题意及思路:https://blog.csdn.net/mmk27_word/article/details/93999633 第一次见这种DP,有点像退背包的思想,如果发现有可能因为字母相同和前面算重时,把这种情况减去. 代码: #include <bits/stdc++.h> #define LL long long using namespace std; const int maxn = 110; int pre[30]; LL dp[maxn][maxn]; char s[maxn]…
题面 Having endured all the hardships, Lara Croft finally found herself in a room with treasures. To her surprise she didn't find golden mountains there. Lara looked around and noticed on the floor a painted table n × m panels in size with integers wri…