DP
文章平均质量分 74
robin_8
这个作者很懒,什么都没留下…
展开
-
RMQ问题模板
#include<bits/stdc++.h>using namespace std;#define MAXN 1000+10int dp[MAXN][MAXN], a[MAXN]; void InitRMQ(int l, int r, int n){ int k = floor((double)log(r-l+1)/log(2)); for (int i = 1; i <=原创 2017-01-22 21:29:08 · 225 阅读 · 0 评论 -
HDU-1248 寒冰王座 (完全背包)
讲道理这题真是背包问题中的水题,第一次写背包如此轻松。 题目: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票(记住,只有一张钞票),为了防止自己在战斗中频繁的死掉,他决定给自己买一些道具,于是他来到了地精商店前. 死亡骑士:”我要买道具!” 地精商人:”我们这里有三种道具,血瓶150块一个,魔法药200块一个,无敌药水350块一个.” 死亡骑士:”好的,给我一个血瓶.”原创 2017-01-03 15:32:32 · 275 阅读 · 0 评论 -
HDU-2955 Robberies (01背包)
题目: The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. He has decided to work in the lucr原创 2017-01-03 16:22:34 · 172 阅读 · 0 评论 -
HDU-2844 Coins (多重背包)
题目: Whuacmers use coins.They have coins of value A1,A2,A3…An Silverland dollar. One day Hibix opened purse and found there were some coins. He decided to buy a very nice watch in a nearby shop. He wa原创 2017-01-04 12:39:10 · 594 阅读 · 1 评论 -
HDU-1059 Dividing (多重背包)
题目: Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the s原创 2017-01-11 17:23:57 · 240 阅读 · 0 评论 -
HDU-1003 Max Sum (dp)
题目: Given a sequence a[1],a[2],a[3]……a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.Input The原创 2017-01-11 20:10:49 · 225 阅读 · 0 评论 -
HDU-3652 B-number (数位DP+模运算)
思路:如果只判断子串是否有13的话非常简单,这题还加了一个条件就是要被13整除这里就要用到模运算的性质,即(a+b+c)%d = a%d + b%d + c%d,因此可以将一个n位数例如1234 % 5改写成(1 * 10^3 + 2 * 10^2 + 3 * 10^1 + 4 * 10^0) % 5 再展开即可。Code:#include<bits/stdc++.h>#define M(a原创 2017-01-20 22:44:47 · 213 阅读 · 0 评论 -
HDU-1087 Super Jumping! Jumping! Jumping! (DP)
Problem Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to yo原创 2017-01-21 13:04:06 · 235 阅读 · 0 评论 -
POJ-3186 Treats for the Cows (区间DP)
Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per day and wants to maximize the money he receives over a原创 2017-01-22 21:15:17 · 205 阅读 · 0 评论 -
HDU-1331 Function Run Fun (记忆化搜索)
最简单的记忆化搜索,题目有点问题,a, b, c中若既满足其中一个不大于0,又满足其中一个大于20,按前一种情况。Code:#include<bits/stdc++.h>using namespace std;int w[21][21][21];int dfs(int a, int b, int c) { if (a <= 0 || b <= 0 || c <= 0) return 1;原创 2017-01-28 19:27:30 · 262 阅读 · 0 评论