![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
线性dp
破晓aa
这个作者很懒,什么都没留下…
展开
-
最长连续子序列和(基础动态规划)
具体意思:给出长度为n的数组让你求最大连续子段和, 输出最大的值;解决方法:定义dp数组, dp[i]代表以第i个数结尾的连续序列和的最大值, 则状态转移方程为: dp[i] = max(dp[i - 1] + a[i], a[i]); 当然, 要记得把dp[0]初始化为0。还有一点要说的是如果输入的数据全是负数的话,...原创 2018-08-02 19:52:15 · 8172 阅读 · 0 评论 -
Codeforces Round #523 (Div. 2) C. Multiplicity (dp)
C. Multiplicitytime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer array原创 2019-01-02 17:04:22 · 209 阅读 · 0 评论 -
Easy Problem(Educational Codeforces Round 57 (Rated for Div. 2) ) (dp)
Vasya is preparing a contest, and now he has written a statement for an easy problem. The statement is a string of length原创 2019-01-02 08:59:45 · 260 阅读 · 0 评论 -
The Battle of Chibi HDU - 5542 (dp + 树状数组 + 离散化)
Cao Cao made up a big army and was going to invade the whole South China. Yu Zhou was worried about it. He thought the only way to beat Cao Cao is to have a spy in Cao Cao's army. But all generals and...原创 2018-12-25 11:19:33 · 208 阅读 · 0 评论 -
K-inversions URAL - 1523 (dp + 线段树优化)
Consider a permutation a 1, a 2, …, an (all ai are different integers in range from 1 to n). Let us call k-inversion a sequence of numbers i 1, i 2, …, ik such that 1 ≤ i 1 < i 2 < … < ...原创 2018-12-11 09:00:23 · 288 阅读 · 0 评论 -
Contest Setting(dp)
A group of contest writers have written n problems and want to use k of them in an upcoming contest. Each problem has a difficulty level. A contest is valid if all of its k problems have different di...原创 2018-11-30 09:48:10 · 823 阅读 · 1 评论 -
Robberies HDU - 2955(01背包)
题目大意:某人要抢劫银行,给出你一个最大被抓的概率p,和银行个数,随后给出每个银行的钱数和被抓的概率,要求在被抓概率小于p的情况下获得的最大的money。题解:妥妥的一道01背包,本来把被抓概率当成01背包中的体积了,只需要把所有概率都×100在处理就好了,后来发现不行,首先对于多个银行都去抢的话概率是相乘的,然后他给的概率不见得就是两位小数的,所以此路不通。仔细想想01背包的内容,遍历一...原创 2018-10-17 16:44:30 · 149 阅读 · 0 评论 -
Number String HDU - 4055(计数dp)
题意:给你一个字符串s,s[i] = 'D’表示排列中a[i] &gt; a[i+1],s[i] = 'I’表示排列中a[i] &lt; a[i+1]。比如排列 {3, 1, 2, 7, 4, 6, 5} 表示为字符串 DIIDID思路:本来想着dp[i][j]用来统计第i个数为j时情况数量,但是好像不可行。参考了众多大神的博客,用dp[i][j]代表1-i的排列(!!!!注意是排列)其中...原创 2018-10-16 17:35:25 · 172 阅读 · 0 评论 -
Working out CodeForces - 429B(dp)
Summer is coming! It’s time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represent...原创 2018-10-10 09:24:52 · 98 阅读 · 0 评论 -
The King’s Ups and Downs HDU - 4489(组合dp)
题目意思:给一个n,求n个高矮不同的人排成一排使得高、矮依次排列的种数。解题思路:他只给了人数,我们假设所有人的身高从低到高排成一列,序号为1,2,3,4…我们从前往后一个一个取,到了第n个人的时候,将这个人放入前n-1个人的序列中去,有n个位置可以放(也就是插空)。显然只有第n个人要插入的位置左边的人是由下降得到的(即他的身高小于他前一个人的身高),并且其右边的人的身高也是要小于他右边的...原创 2018-10-15 20:46:58 · 208 阅读 · 0 评论 -
Mex HDU - 4747(dp)
https://cn.vjudge.net/problem/HDU-4747[题目传送门]解题方案:既然想用dp的方法解决这个问题,最容易想到的就是用递推解决,难点就在于如何定义从始到终的状态以及如何由上一个状态推出下一个状态,有时候状态的递推不是一个简单的递推式。pos[i] 存放的是与i相等的数中最靠右端的数的位置。full[a[i]] 表示完全覆盖[0, a[i]]中的所有数的区间的...原创 2018-10-15 20:07:46 · 349 阅读 · 0 评论 -
Coin Toss UVA - 10328(dp + 高精度)
Toss is an important part of any event. When everything becomes equal toss is the ultimate decider.Normally a fair coin is used for Toss. A coin has two sides head(H) and tail(T). Superstition may wo...原创 2018-10-12 20:58:59 · 249 阅读 · 0 评论 -
最长上升子序列(两种方法)
常规方法:(n^2)#include<iostream> using namespace std;int i,j,n,a[100],b[100],max; int main() { cin>>n; for(i=0;i<n;i++) cin>>a[i]; b[0]=1; //初始化,以a[0]结尾的最长递增...原创 2018-09-27 21:04:44 · 1922 阅读 · 0 评论 -
最长公共子序列
#include <iostream>#include <cstring>using namespace std;int dp[1000][1000];string st1, st2;int main(){ while(cin >> st1 >> st2) { int len1 = st1.size();...原创 2018-08-06 21:19:01 · 130 阅读 · 0 评论 -
Codeforces Round #522 C. Playing Piano(dp)
Little Paul wants to learn how to play piano. He already has a melody he wants to start with. For simplicity he represented this melody as a sequence a1,a2,…,ana1,a2,…,an of key numbers: the more a nu...原创 2019-01-08 19:53:17 · 172 阅读 · 1 评论