
DP动态规划
文章平均质量分 81
RJ28
小学生
展开
-
Hdu-4507 吉哥系列故事——恨7不成妻(数位DP)
Description 单身! 依然单身! 吉哥依然单身! DS级码农吉哥依然单身! 所以,他生平最恨情人节,不管是214还是77,他都讨厌! 吉哥观察了214和77这两个数,发现: 2+1+4=7 7+7=7*2 77=7*11 最终,他发现原来这一切归根到底都是因为和7有关!所以,他现在甚至讨厌一切和7原创 2016-08-19 21:32:56 · 379 阅读 · 0 评论 -
Codeforces Beta Round #8 E. Beads(数位DP)
One Martian boy called Zorg wants to present a string of beads to his friend from the Earth — Masha. He knows that Masha likes two colours: blue and red, — and right in the shop where he has come, the原创 2016-10-20 12:45:58 · 856 阅读 · 0 评论 -
UVALive-3683 A Scheduling Problem(treedp)
题意: 有n(nB表示A必须在B之前完成,A-B表示A和B不能在同一天晚上。输入保证约束图是将一颗树的一些边定向之后得到的。分析: 这题好神,我一开始根据题目的提示想了个错误的贪心,然后疯狂WA了一天。 我一开始错误的贪心是认为对于原图最长链k大于2的情况,答案为k+1当且仅当只有一个无向边定向后参与入了新的最长链的构造,于是我一开始的做法就是特判k = 2的情况原创 2016-11-29 10:30:37 · 774 阅读 · 1 评论 -
Hdu-5915 The Fastest Runner Ms. Zhang(环套树DP)
Problem DescriptionMs. Zhang is a journalist from Hong Kong, and she runs very very fast, so every one calls her “The fastest runner”. There are n cities (numbered from 1 to n) and n roads in the co原创 2016-11-01 21:58:00 · 901 阅读 · 0 评论 -
UVALive-3637 The Bookcase(DP)
题意:有n(3分析:这题的状态表示很精妙,f[j][k]表示除了最高书所在层外的另外两层的宽度为j 和 k(最后最高层的宽度就是tot - j - k)时的最小总高度,这样做是枚举比较小的宽度来约束高度,如果能想到这个状态表示那么转移也就很自然了。#include#include#include#include#include#include#inclu原创 2016-11-29 20:38:06 · 343 阅读 · 0 评论 -
Poj-1155 TELE(树形背包)
DescriptionA TV-network plans to broadcast an important football match. Their network of transmitters and users can be represented as a tree. The root of the tree is a transmitter that emits the f原创 2016-12-14 21:24:49 · 394 阅读 · 0 评论 -
Codeforces Round #382 (Div. 1) C. Ostap and Tree(树形DP)
Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph.Ostap's tree now has n vertices. He wants t原创 2016-12-06 17:30:12 · 570 阅读 · 0 评论 -
Poj-3570 Fund Management(状态压缩动态规划)
题意:你有c美元,但是没有股票。给m天时间和n支股票供逆买卖(c 分析:原创 2016-11-24 22:26:08 · 500 阅读 · 0 评论 -
Hdu-1561 The more, The Better(树形依赖背包)
ACboy很喜欢玩一种战略游戏,在一个地图上,有N座城堡,每座城堡都有一定的宝物,在每次游戏中ACboy允许攻克M个城堡并获得里面的宝物。但由于地理位置原因,有些城堡不能直接攻克,要攻克这些城堡必须先攻克其他某一个特定的城堡。你能帮ACboy算出要获得尽量多的宝物应该攻克哪M个城堡吗? Input每个测试实例首先包括2个整数,N,M.(1 = 0。当N = 0, M = 0输入结束。原创 2016-12-13 16:20:20 · 307 阅读 · 0 评论 -
Codeforces Beta Round #23 E. Tree(DP+高精度)
Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the produc原创 2016-12-23 23:17:30 · 380 阅读 · 0 评论 -
Codeforces Round #385 (Div. 1) C. Hongcow Buys a Deck of Cards(DP/模拟退火)
One day, Hongcow goes to the store and sees a brand new deck of n special cards. Each individual card is either red or blue. He decides he wants to buy them immediately. To do this, he needs to play原创 2016-12-19 15:07:04 · 621 阅读 · 0 评论 -
Uva-10559 Blocksf(DP)
题意:给n(小于200)个砖块,每个砖块有自己的颜色,你每次可以选择一段颜色相等的砖块然后把它消去,得分为长度的平方,问你这段砖块最多能得多少分。分析:黑书上的经典DP,以前写过,今天趁着忘了又试着写了写,然后发现自己怎么个搞不出来状态的表示方法。。。f[i,j,k]表示 [i,j]这一段砖块后边再接上长度为k的颜色和第j块一样的砖块的最高得分,然后我们发现只要讨论原创 2016-11-09 19:54:06 · 350 阅读 · 0 评论 -
CodeForces - 19E Fairy(图论 + DP)
DescriptionOnce upon a time there lived a good fairy A. One day a fine young man B came to her and asked to predict his future. The fairy looked into her magic ball and said that soon the fine you原创 2016-11-07 16:02:25 · 426 阅读 · 0 评论 -
Codeforces Round #370 (Div. 2) D. Memory and Scores(DP)
Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with scorea and Lexa starts with score b. In a single turn, both Memory and Lexa get some i原创 2016-09-11 23:12:13 · 326 阅读 · 0 评论 -
AIM Tech Round 3 (Div. 1) C. Centroids(树形DP)
C. Centroidstime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputTree is a connected acyclic graph. Suppose you are given原创 2016-09-06 21:54:00 · 370 阅读 · 0 评论 -
Hdu-5816 Hearthstone(状态压缩DP)
Problem DescriptionHearthstone is an online collectible card game from Blizzard Entertainment. Strategies and luck are the most important factors in this game. When you suffer a desperate situation原创 2016-08-09 22:37:56 · 596 阅读 · 2 评论 -
LA 7344 Numbered Cards(数位DP)
题意:给定n,选择一些小于等于n的数构成一个集合,使得集合内各个元素的十进制表示形式没有重叠的数字,问这样的集合有多少个。分析:一共十个数字,我们可以枚举单个数字的所有组合情况(一千种),然后用数位DP求出符合每种组合的所有单个数字的个数,设f[x]表示数字集合为x的个数,我们可以利用用状压DP的方式求出f[x]的值。#include#include#include#原创 2016-08-22 14:31:02 · 403 阅读 · 0 评论 -
Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend(贪心+DP)
Sonya was unable to think of a story for this problem, so here comes the formal description.You are given the array containing n positive integers. At one turn you can pick any element and increase原创 2016-09-14 17:30:59 · 428 阅读 · 0 评论 -
Hdu-5898 odd-even number(数位DP)
Problem DescriptionFor a number,if the length of continuous odd digits is even and the length of continuous even digits is odd,we call it odd-even number.Now we want to know the amount of odd-even n原创 2016-09-20 12:50:59 · 394 阅读 · 0 评论 -
Hdu-5900 QSC and Master(区间DP)
Problem DescriptionEvery school has some legends, Northeastern University is the same.Enter from the north gate of Northeastern University,You are facing the main building of Northeastern Univer原创 2016-09-20 12:59:33 · 333 阅读 · 0 评论 -
Hdu-5886 Tower Defence(树形DP)
Problem DescriptionThere was a civil war between two factions in Skyrim, a province of the Empire on the continent of Tamriel. The Stormcloaks, led by Ulfric Stormcloak, are made up of Skyrim's nati原创 2016-09-20 22:12:31 · 906 阅读 · 0 评论 -
Codeforces Beta Round #10 D. LCIS(DP)
DescriptionThis problem differs from one which was on the online contest.The sequence a1, a2, ..., an is called increasing, ifai ai + 1 fori n.The sequence s1, s2, ..., sk is called the原创 2016-10-23 21:38:18 · 336 阅读 · 0 评论 -
CodeForces - 17C Balance(DP)
DescriptionNick likes strings very much, he likes to rotate them, sort them, rearrange characters within a string... Once he wrote a random string of characters a, b, c on a piece of paper and b原创 2016-11-06 20:35:52 · 879 阅读 · 0 评论 -
Codeforces Beta Round #11 D. A Simple Task(状压DP)
Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges.InputThe first line of input contains two integers n and m (1 ≤ n ≤ 19,原创 2017-02-06 16:11:38 · 493 阅读 · 0 评论 -
RCC 2014 Warmup (Div. 2) D. Cunning Gena(状压DP)
A boy named Gena really wants to get to the "Russian Code Cup" finals, or at least get a t-shirt. But the offered problems are too complex, so he made an arrangement with his n friends that they wil原创 2017-02-07 21:50:33 · 298 阅读 · 0 评论 -
2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest - J. Bottles(DP)
Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda ai and bottle volumebi (ai ≤ bi).Nick has decided to pour all remaining soda原创 2017-02-09 22:01:43 · 669 阅读 · 0 评论 -
Hdu-5763 Another Meaning(DP+KMP)
Another MeaningTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 558 Accepted Submission(s): 262Problem DescriptionAs is known to a原创 2016-07-29 13:49:50 · 412 阅读 · 0 评论 -
Uva-10271 Chopsticks(DP)
题意:佳佳的一套筷子有三只,两根短筷子和一只比较长的.如果一套筷子的长度分别为a,b,c,(a 分析:设f[i][j]表示当前已经凑齐了j双筷子,并且最后一套筷子中最小的那根为i的最小质量和,如果3*j > n-i+1那么当前状态一定不合法,有个这个状态我们发现只要处理下上个阶段的后缀最小值就能实现O(1)转移了.#include #define N 10005#define原创 2017-04-14 15:30:01 · 436 阅读 · 0 评论 -
Uva-1629 Cake slicing(DP)
题意:给出一个由大写字母组成的长度为n(n 分析:f[i][j]表示把i到j这一段压缩后的最小长度,那么f[i][j] = min(f[i][k]+f[k+1][j]),如果[i,j]这一子串存在循环节的话还要处理一下折叠的情况.#include #define N 100005#define INF 1047483647using namespace std;ty原创 2017-04-06 16:02:10 · 321 阅读 · 0 评论 -
Xiangtan Invitation Contest 2017 - J Similar Subsequence(DP)
For given sequence A = (a1, a2, . . . , an), a sequence S = (s1, s2, . . . , sn) has shape A if and only if:• si = min{si, si+1, . . . , sn} for all ai = 0;• si = max{si, si+1, . . . , sn} for all a原创 2017-05-16 21:39:42 · 635 阅读 · 0 评论 -
CCNU校赛2017 - F 康康撩妹(斜率DP)
分析:大概就是f[i][j] = min (f[k][j-1] + w[k+1][i])这种形式的DP,我们把w函数拆开可以得到一个斜率为-dis[i][n]的等式,随着i的增大斜率也在不断增大,所以我们维护一个下凸的决策队列,这样能把转移复杂度优化到O (1).题目链接:https://acm.whu.edu.cn:8443/problem/663#include #define IN原创 2017-05-08 23:08:21 · 581 阅读 · 0 评论 -
Hdu-5519 Kykneion asma(状压DP+容斥)
On the last day before the famous mathematician Swan's death, he left a problem to the world: Given integers nn and aiai for 0≤i≤40≤i≤4, calculate the number of nn-digit integers which have at mos原创 2017-07-29 22:31:32 · 820 阅读 · 0 评论 -
Hdu-4661 Message Passing(树形DP)
There are n people numbered from 1 to n. Each people have a unique message. Some pairs of people can send messages directly to each other, and this relationship forms a structure of a tree. In one tur原创 2017-08-02 21:54:33 · 298 阅读 · 0 评论 -
Hdu-6086 Rikka with String(AC自动机+DP)
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:Yuta has n01 strings si, and he wants to原创 2017-08-10 00:25:09 · 372 阅读 · 0 评论 -
Hdu-6212 Zuma(区间DP)
Think about the Zuma Game. You have a row of at most 200black(0) or white(1) balls on the table at the start. Each three consecutive balls never share the same colour. You also have infinite amo原创 2017-09-20 12:38:00 · 437 阅读 · 0 评论 -
2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 D. Hack Portals(区间DP)
We all have much to be proud of.As a player of the game Ingress, IloveMATH is proud of these portals on the road in front of his campus.Here is a brief introduction of this mobile game. Ingress, a原创 2017-09-21 20:31:42 · 549 阅读 · 0 评论 -
Uva-1628 Pizza Delivery(机智DP)
题意:你是一个披萨店的老板,有一天突然收到了n个客户的订单(n 分析:这题有个特点就是如果ei-ti#include using namespace std;int t,T,n,p[105],e[105],f[105][105][2][105],vis[105][105][2][105];int dfs(int l,int r,int op,int k原创 2017-04-05 15:45:11 · 1035 阅读 · 0 评论 -
Uva-1375 The Best Name for Your Baby(复杂DP)
分析:所有的文法都能拆分成A=S1S2这种形式,设状态f[i]j]表示字符i能生成的长度为j的字典序最小字符串,那么f[i][j] = min(f[k][j'] + f[l][j-j']),但是这样会有同层转移的情况,这种情况下状态之间会产生环,我们需要把这种情况拿出来特盘一下(单独跑一遍dij).#include using namespace std;typedef pair原创 2017-04-04 16:06:29 · 732 阅读 · 0 评论 -
Hdu-5921 Binary Indexed Tree(数位DP)
Problem DescriptionRecently, Mr. Frog has learned binary indexed tree. Here is the code of adding t to the interval [1,x]: void add (int x, int t ){ for (int i = x; i != 0; i -= i & (-i原创 2017-01-31 14:27:28 · 1037 阅读 · 0 评论 -
Codeforces Round #259 (Div. 1) B. Little Pony and Harmony Chest(状压dp)
Princess Twilight went to Celestia and Luna's old castle to research the chest from the Elements of Harmony.A sequence of positive integers bi is harmony if and only if for every two elements原创 2017-02-03 11:08:26 · 640 阅读 · 0 评论