
贪心法 DP
文章平均质量分 77
ChasingWaves
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
2014.7.14 CodeForces C题 字符串上的动态规划
题目大意是给你一个序列,让你最多改动一个点,求它的最长原创 2014-07-14 12:03:34 · 488 阅读 · 0 评论 -
hdu 4284 Travel Floyd+TSP
#include #include #include #include #include using namespace std;const int MAX_N = 100 + 5;const int MAX_M = 5000 + 5;const int INF = 0x7fffffff;int d[MAX_N][MAX_N];int dp[1<<15];struct n原创 2014-08-02 16:36:53 · 418 阅读 · 0 评论 -
植物大战僵尸
但是,这次僵尸来进攻时,这些格子里放的不是植物,而是脑子。僵尸不敢独吞,而是想把脑子收集回去给他的K个朋友一起分享,为了不引发各种麻烦,因此他收集的脑子是K+1的倍数。假设僵尸在地图的下方,而他的家在地图上方,另外,这只僵尸不喜欢走直线,喜欢走斜线,因此他每次只会往左上角走或者往右上角走,每走到一个格子会把这个格子的所有脑子都收集起来,问,怎么走收集的脑子个数最多?他可以在最下方任意选择一个格原创 2014-08-05 10:57:41 · 804 阅读 · 0 评论 -
截柱子
题目描述有n根柱子竖在地面上排成一排,每根柱子都可以从顶端截下一段以此来调整为任意高度,但是,柱子被截后剩下的高度必须是大于等于1的整数。相邻两根柱子的距离为w。现在要用一条绳子从第一根柱子的端点按顺序经过每一根柱子的端点到达最后一根绳子的端点,求这根绳子最长需要用多长?输入格式第一行输入一个数T,表示测试数据个数,对于每个测试数据,第一行输入两个整数n,w,分别表示柱子个数和相邻两根原创 2014-08-05 11:13:58 · 592 阅读 · 0 评论 -
POJ 2533 Longest Ordered Subsequence
DescriptionA numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK), where 1 <= i1 < i2 < .原创 2014-03-06 17:09:05 · 519 阅读 · 0 评论 -
携程编程预选赛 B题 括号匹配
描述给你一个字符串,里面只包含"(",")","[","]"四种符号,请问你需要至少添加多少个括号才能使这些括号匹配起来。如:[]是匹配的([])[]是匹配的((]是不匹配的([)]是不匹配的输入第一行输入一个正整数N,表示测试数据组数(N每组测试数据都只有一行,是一个字符串S,S中只包含以上所说的四种字符,S的长度不超过100输出对于每组测试数据都原创 2014-04-10 23:57:55 · 1428 阅读 · 0 评论 -
BZOJ 1010 单调队列优化dp
#include using namespace std;typedef long long LL;#define sqr(a) ((a)*(a))LL c[600000], dp[600000], n, l, L;struct node{ int l, r, s; node(int L=0, int R=0; int S=0) : l(L), r(R), s(S)转载 2014-04-19 10:53:32 · 498 阅读 · 0 评论 -
POJ 1631 最长上升子序列O(nlogn)
/*POJ1631 AC */#include #include using namespace std;int BinSearch(int* a, int len, int num){ int left=0, right = len, mid; while(left <= right) { mid = left+(right-left)/2;原创 2014-03-14 13:44:23 · 563 阅读 · 0 评论 -
WOJ 武大校赛 Problem 1537 - A - Stones I
DescriptionXiaoming took the flight MH370 on March 8, 2014 to China to take the ACM contest in WHU. Unfortunately, when the airplane crossing the ocean, a beam of mystical light suddenly lit up th原创 2014-04-01 21:34:51 · 786 阅读 · 0 评论 -
poj 3616 Milking Time
DescriptionBessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that she decides to schedule her next N (1 ≤ N ≤ 1,000,000) hours (conveniently labeled 0..N原创 2014-04-09 13:47:17 · 397 阅读 · 0 评论 -
poj 2229 Sumsets
DescriptionFarmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer power of 2. Here are the possible sets of原创 2014-04-08 21:10:41 · 435 阅读 · 0 评论 -
hdu 1257 最少拦截系统
Problem Description某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求原创 2014-04-12 10:12:46 · 489 阅读 · 0 评论 -
POJ 1050 To the Max 最大子矩阵和 简单dp
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 39056 Accepted: 20627DescriptionGiven a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub原创 2014-04-03 22:22:21 · 495 阅读 · 0 评论 -
UVa 11991
map演示 #include #include #include using namespace std;map > a;int main(){ int n, m, x, y; while(scanf("%d%d", &n, &m) == 2) { a.clear(); for(int i=0; i<n; i++)转载 2014-02-12 12:02:39 · 516 阅读 · 0 评论 -
poj 2385 Apple Catching
DescriptionIt is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, each full of apples. Bessie cannot reach the apple原创 2014-04-08 23:36:59 · 650 阅读 · 0 评论 -
UVa 10881 - Piotr's Ants
Piotr's AntsTime Limit: 2 secondsPiotr likes playing with ants. He has n of them on a horizontal pole L cm long. Each ant is facing either left or right and walks at a constant speed of 1 cm/s.转载 2014-02-04 17:35:27 · 511 阅读 · 0 评论 -
hdu 4905 The Little Devil II 多校第四场 DP
Given a sequence a_1,a_2,...,a_n, if we can take some of them(each a_i can only be used once), and they sum to k, then we say this sequence is a good sequence.How many good sequence are there? Giv原创 2014-08-01 13:14:25 · 537 阅读 · 0 评论 -
POJ 4901 The Romantic Hero DP
//890MS 12388K#include #include #include using namespace std;typedef long long ll;const int maxa = 1024;const int maxn = 1000;const int mod = int(1e9) + 7;int f[maxn+5][maxa], g[maxn+5][maxa原创 2014-08-02 11:56:09 · 560 阅读 · 0 评论 -
POJ 2976 Dropping tests 0/1分数规划问题 最大化平均值 贪心+二分
DescriptionIn a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be.Given your test scores and a positive intege原创 2014-06-24 11:35:56 · 605 阅读 · 0 评论 -
POJ 2836 Rectangular Covering 状态压缩DP 几何
Descriptionn points are given on the Cartesian plane. Now you have to use some rectangles whose sides are parallel to the axes to cover them. Every point must be covered. And a point can be covere原创 2014-06-18 12:44:00 · 788 阅读 · 1 评论 -
POJ 2441 Arrange the Bulls 状态压缩DP
题目链接:http://poj.org/problem?id=2441原创 2014-05-28 00:09:50 · 473 阅读 · 0 评论 -
poj 2184 Cow Exhibition
题目链接:http://poj.org/problem?id=2184转载 2014-05-06 15:52:38 · 426 阅读 · 0 评论 -
poj 1065 Wooden Sticks
DescriptionThere is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some原创 2014-04-27 01:19:10 · 427 阅读 · 0 评论 -
POJ 3614 Sunscreen 贪心 优先队列
这题的模型是给你一些线段和一些点,每个点的使用次数都是有一定限制的,每条线段只能被标记一次,求最多有多少条线段被标记。将奶牛按照阳光强度的最小值从小到大排序。将防晒霜也按照能固定的阳光强度从小到大排序从最小的防晒霜枚举,将所有符合 最小值小于等于该防晒霜的 奶牛的 最大值 放入优先队列之中。然后优先队列是小值先出所以就可以将这些最大值中的最小的取出来。更新答案。原创 2014-07-19 14:56:55 · 431 阅读 · 0 评论 -
POJ 3253 Fence Repair 霍夫曼树 贪心 优先队列
非常经典的一道原创 2014-07-18 16:15:07 · 557 阅读 · 0 评论 -
POJ 3069 Saruman's Army 线段的覆盖 贪心
把做过的题写一写吧原创 2014-07-18 00:44:23 · 429 阅读 · 0 评论 -
POJ 3045 Cow Acrobats 贪心
题目链接:http://poj.org/problem?id=3045原创 2014-06-24 10:20:59 · 679 阅读 · 0 评论 -
POJ 2836 Rectangular Covering 状态压缩DP
Descriptionn points are given on the Cartesian plane. Now you have to use some rectangles whose sides are parallel to the axes to cover them. Every point must be covered. And a point can be covere原创 2014-06-07 22:20:44 · 495 阅读 · 0 评论 -
POJ 3254 Corn Fields 状态压缩DP
题目链接原创 2014-06-02 12:11:46 · 523 阅读 · 0 评论 -
poj 2392 Space Elevator
DescriptionThe cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) different types of blocks with which to原创 2014-05-03 11:58:04 · 433 阅读 · 0 评论 -
POJ 3666 Making the Grade 滚动数组+状态压缩DP
题目链接:点击打开链接原创 2014-05-01 21:05:18 · 536 阅读 · 0 评论 -
多重背包O(N*V)算法详解(使用单调队列)(转)
多重背包问题:有N种物品和容量为V的背包,若第i种物品,容量为v[i],价值为w[i],共有n[i]件。怎样装才能使背包内的物品总价值最大?网上关于“多重背包”的资料倒是不少,但是关于怎么实现O(N*V)算法的资料,真得好少呀,关于“单调队列”那部分算法,又没说明得很清楚,看了几遍没看懂原理,只好自己动脑去想怎么实现O(N*V)算法。若用F[i][j]表示对转载 2014-04-12 11:48:46 · 626 阅读 · 0 评论 -
POJ 2686 Traveling by Stagecoach 状态压缩DP
题目链接: http://poj.org/problem?id=2686原创 2014-05-25 11:47:19 · 549 阅读 · 0 评论 -
poj 3176 Cow Bowling
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 13015 Accepted: 8597DescriptionThe cows don't use actual bowling balls when they go bowling. They each take a number (in the range 0..原创 2014-04-08 20:36:15 · 376 阅读 · 0 评论