![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
动态规划
wchhlbt
这个作者很懒,什么都没留下…
展开
-
codeforces 447C DZY Loves Sequences(最长上升子序列变体)
DescriptionDZY has a sequence a, consisting of n integers.We'll call a sequence ai, ai + 1, ..., aj(1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value(j - i + 1) denotes the length o原创 2016-05-07 20:12:30 · 454 阅读 · 0 评论 -
POJ 2411 Mondriaan's Dream (状压dp)
题目原文:Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, for原创 2017-02-21 20:21:24 · 325 阅读 · 0 评论 -
Ural 1018 Binary Apple Tree (树形dp)
Let's imagine how apple tree looks in binary computer world. You're right, it looks just like a binary tree, i.e. any biparous branch splits up to exactly two new branches. We will enumerate by inte原创 2017-02-15 13:05:46 · 313 阅读 · 0 评论 -
POJ 2342 Anniversary party (树形dp)
题目描述: There is going to be a party to celebrate the 80-th Anniversary of the Ural State University. The University has a hierarchical structure of employees. It means that the supervisor relation fo原创 2017-02-15 12:47:43 · 271 阅读 · 0 评论 -
codeforces 788C The Great Mixing (bitset优化dp、bfs)
题目原文 http://codeforces.com/problemset/problem/788/CSasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentra原创 2017-03-31 17:17:20 · 1549 阅读 · 0 评论 -
codeforces 803E Roma and Poker (dp)
题目原文:http://codeforces.com/contest/803/problem/EE. Roma and PokerEach evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there原创 2017-05-01 10:43:05 · 395 阅读 · 0 评论 -
codeforces 560E Gerald and Giant Chess (dp + 组合数)
题目原文:http://codeforces.com/contest/560/problem/EE. Gerald and Giant ChessGiant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the gam原创 2017-05-11 20:18:32 · 369 阅读 · 0 评论 -
2017百度之星复赛 hdu 6148 Valley Numer (数位dp)
题目原文:Valley NumerTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 343 Accepted Submission(s): 180Problem Description众所周知原创 2017-08-18 22:41:13 · 578 阅读 · 0 评论 -
hihocoder 1033 交错和 (数位dp)
描述给定一个数 x,设它十进制展从高位到低位上的数位依次是 a0, a1, ..., an - 1,定义交错和函数:f(x) = a0 - a1 + a2 - ... + ( - 1)n - 1an - 1例如:f(3214567) = 3 - 2 + 1 - 4 + 5 - 6 + 7 = 4给定 输入输入数据仅一行原创 2017-09-13 19:22:44 · 279 阅读 · 0 评论 -
codeforces 401D Roman and Numbers (数位dp)
题目大意http://codeforces.com/problemset/problem/401/DD. Roman and NumbersRoman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja chang原创 2017-09-14 13:57:56 · 482 阅读 · 0 评论 -
codeforces 837D Round Subset (dp)
解题思路:题目有很明显的dp特征(涉及多种状态和状态之间的关系)。我们考虑状态的定义,很容易知道尾0的个数取决于因子2和5中次数较小的一个。设状态 dp[i][j][k] 表示前i个数中选取j个并且这j个数的乘积包含的5的幂次为k的情况下 乘积包含2的最大幂次最后的答案就是遍历第三维的取值,找到2和5最小值最大的情况。需要注意的是,如果直接开成这样的三维数组可能会MLE,所以我们可原创 2017-09-30 16:04:22 · 225 阅读 · 0 评论 -
codeforces 587B Duff in Beach (dp)
B. Duff in BeachWhile Duff was resting in the beach, she accidentally found a strange array b0, b1, ..., bl - 1 consisting of lpositive integers. This array was strange because it was extrem原创 2017-10-02 20:10:44 · 304 阅读 · 0 评论 -
codeforces 712D Memory and Scores (dp)
D. Memory and ScoresMemory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score a and Lexa starts with score b. In a single turn, both原创 2017-10-03 20:49:18 · 334 阅读 · 0 评论 -
Wanafly 挑战赛3 A 珂学送分 (dp)
解题思路从后往前考虑,令dp[i] 为从i-n这段区间可以切成的期望段数,从后往前就比较好转移了。dp[i]=1j−i+1∑k=i+1j+1dp[k]+1 dp[i] = \frac{1}{j-i+1}\sum_{k=i+1}^{j+1}dp[k] + 1AC代码/** @Author: wchhlbt* @Last Modified time: 2017-11-17*/#include <b原创 2017-11-17 16:21:03 · 462 阅读 · 0 评论 -
整数拆分问题 动态规划解法
题目链接我们想要整数 M 拆分成 N 个正数的方案数我们定义 dp[i][j] 将整数 j 拆分为 i 个正数之和那么我们分情况考虑,这 i 个正数中是否包含1如果包含 我们可以先去掉这个1,方案数就是 dp[i-1][j-1]如果不包含 也就是说所有 i 个正数都 ≥2 那么我们可以把每个数都减一 方案数为 dp[i][j-i]初始条件是 dp[0][0原创 2017-11-05 13:36:54 · 6791 阅读 · 4 评论 -
codeforces 768D Jon and Orbs (概率dp)
题目原文:Jon Snow is on the lookout for some orbs required to defeat the white walkers. There arek different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weir原创 2017-02-21 16:53:41 · 393 阅读 · 0 评论 -
UVA 147 Dollars (子集和问题 & DP)
题目:New Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins. Write a program that will determine, for any given amount, in how many ways that amount ma原创 2017-02-11 15:50:43 · 341 阅读 · 0 评论 -
hdu 2546 饭卡(0-1背包问题)
饭卡Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 19943 Accepted Submission(s): 6939Problem Description电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之原创 2016-04-16 11:13:31 · 428 阅读 · 0 评论 -
hdu 1171 Big Event in HDU(0-1背包问题)
Big Event in HDUTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 33389 Accepted Submission(s): 11622Problem DescriptionNowadays,原创 2016-04-16 11:04:50 · 310 阅读 · 0 评论 -
hdu 1114 Piggy-Bank(完全背包问题)
解题思路:完全背包问题#include #include #include using namespace std;#define inf 0x3f3f3f3fint val[505];int weight[505];int dp[10005];int main(){ //freopen("test.txt","r",stdin); int t,i,j;原创 2016-04-28 21:15:19 · 561 阅读 · 0 评论 -
hdu 2544 最短路 (Floyd-Warshall)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2544解题思路:本题采用Floyd-Warshall算法(动态规划思想)求最短路,需要注意本题为无向图。AC代码:#include #include #include #define inf 0x3f3f3f3f //定义一个极其大的数using namespac原创 2016-04-30 16:06:31 · 471 阅读 · 0 评论 -
hdu 2066 一个人的旅行(最短路)
解题思路:应该是最短路问题Dijkstra算法,虽然想到了超时,还是写了一个Floyd-Warshall版本,不过果断TLE了。。。先放一个TLE代码:#include #include #include #define inf 0x3f3f3f3fusing namespace std;int dp[1005][1005];int S[1005],D[1005];i原创 2016-04-30 17:26:43 · 431 阅读 · 0 评论 -
POJ 1631 Bridging signals(最长上升子序列 nlgn做法)
传送门:http://poj.org/problem?id=1631Bridging signalsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 12687 Accepted: 6915Description'Oh no, they've done原创 2016-05-30 21:41:26 · 453 阅读 · 0 评论 -
URAL 1119 Metro (动态规划)
解题思路:由题意可以容易得到递推式(dp[i][j]表示到坐标为(i,j)的点所需的距离)if(存在斜边)dp[i][j] = min(dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]+1.414)elsedp[i][j] = min(dp[i-1][j]+1,dp[i][j-1]+1)所以只需要按照递推式从下至上,从左至右递推即可。#inclu原创 2016-07-26 17:04:23 · 333 阅读 · 0 评论 -
hdu 5616 Jam's balance ( 动态规划 )
DescriptionJim has a balance and N weights. The balance can only tell whether things on different side are the same weight. Weights can be put on left side or right side arbitrarily. Ple原创 2016-07-27 20:13:15 · 757 阅读 · 1 评论 -
hdu 5410 CRB and His Birthday(0-1背包+完全背包)
CRB and His BirthdayTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1605 Accepted Submission(s): 755Problem DescriptionToday is原创 2016-08-04 18:45:18 · 350 阅读 · 0 评论 -
hdu 3555 Bomb (数位dp)
题目大意:给定一个数n,问你从1--n之中有多少个数含有49这个子串,1-50中就只有49符合条件。解题思路:因为是初学数位dp,这是自己根据模板写的第一道题,我设计的dp[i][j]表示的含义是i位数字,并且他的前一位是数字j,从1-这个数字中不包含49字串的个数。具体可以参考代码。 这里简单介绍一下我所了解的数位dp,所谓数位dp,无非就是根据每一位数字的情况来进行判原创 2016-08-04 17:14:11 · 516 阅读 · 1 评论 -
hdu 2089 不要62(数位DP/暴力)
不要62Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 34126 Accepted Submission(s): 12309Problem Description杭州人称那些傻乎乎粘嗒嗒的人为62(音:l原创 2016-08-04 19:16:45 · 371 阅读 · 0 评论 -
codefoces 706C Hard problem (dp/dfs)
C. Hard problemhttp://codeforces.com/problemset/problem/706/CVasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help.Vasiliy is原创 2016-08-12 20:16:06 · 340 阅读 · 0 评论 -
hdu 5898 odd-even number (数位dp)
odd-even numberTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 661 Accepted Submission(s): 362Problem DescriptionFor a number原创 2016-09-24 16:27:17 · 383 阅读 · 0 评论 -
UVA 10944 Nuts for nuts.. (状态压缩dp)
题目描述:So as Ryan and Larry decided that they don’t really taste so good, they realized that there are some nuts located in certain places of the island.. and they love them! Since they’re lazy, but g原创 2017-02-16 11:42:17 · 375 阅读 · 0 评论 -
POJ 1141 Brackets Sequence (区间DP + DFS )
解题思路:想要达到最小的长度,关键在于找到合适的位置为不配对的符号配对。如何找到合适的位置呢? 对每一个合适的位置来说,如果从该处将字符串中断,两边所添加的字符总数将会最少。 所以也就是说要求出任意一段字符串所需要添加的字符数量(最小值)还有需要中断的位置。(有点分治的思想)AC代码:#include #defi原创 2017-02-10 19:40:18 · 255 阅读 · 0 评论 -
2017 ICPC 北京站 H (hihocoder 1634) Puzzle Game (dp 最大子矩阵和)
解题思路:很容易想到的是如果需要修改的话我们一定要对最大子矩阵的内部修改。不然最大值始终不变。所以我们需要维护出最大子矩阵的位置,那么如果有多个最大子矩阵怎么办呢?维护任意一个即可。后面会说明原因。然后枚举最大子矩阵里面的点,修改这个点我们能得到的当前矩阵的最大子矩阵和应该等于 max(上方最大子矩阵和,下方最大子矩阵和,左方最大子矩阵和,右方最大子矩阵和,包含这个点后的最大子矩阵原创 2017-11-20 13:50:18 · 1759 阅读 · 0 评论