Milking Time POJ - 3616 dp 感觉像背包】的更多相关文章

#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> using namespace std; ; struct edge{ int start; int end; int w; }e[N]; bool cmp(edge a,edge b) { return a.start<b.start; } int dp[N]; int main() { int n,m,…
题意:给你N的时间,M的工作时间段,每个时间段有一个权重,还有一个R,每次完成一个工作需要休息R,问最后在时间N内,最大权重是多少. 思路:很简单的DP,首先对区间的右坐标进行排序,然后直接转移方程就是dp[i] = max(dp[i] , dp[j] + work[i].c) ,判断条件就是这两个区间加上一个休息时间R是否会相交. #include <set> #include <map> #include <stack> #include <cmath>…
Description The cow bicycling team consists of N (1 <= N <= 20) cyclists. They wish to determine a race strategy which will get one of them across the finish line as fast as possible. Like everyone else, cows race bicycles in packs because that's th…
题目链接:http://poj.org/problem?id=1745 Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13431   Accepted: 4774 Description Consider an arbitrary sequence of integers. One can place + or - operators between integers in the sequen…
POJ 3181 Dollar Dayz(全然背包+简单高精度加法) id=3181">http://poj.org/problem?id=3181 题意: 给你K种硬币,每种硬币各自是1美元,2美元-K美元且能够无限使用,问你用上面K种硬币构成n美元的话有多少种方法? 分析: 本题是一道明显的全然背包问题, 只是本题还能够换一种方法来看: 整数n由前K个自然数构造, 一共同拥有多少种方法? (尽管本题要用到高精度加法, 可是非常easy, 不要被吓到哦) 首先是DP部分: 令dp[i][…
POJ 3211 Washing Clothes(01背包) http://poj.org/problem?id=3211 题意: 有m (1~10)种不同颜色的衣服总共n (1~100)件.Dearboy和她的girlfriend两个人要一起洗完所有衣服,为了预防色彩混合,他们每次仅仅能同一时候洗同一种颜色的衣服,给出洗完每件衣服所需的时间time和它的颜色color,求出Dearboy和她的girlfriend最少用多少时间能洗完毕所有衣服. 分析: 因为每种颜色的衣服是分开洗的, 所以我们…
链接:Piggy-Bank 大意:已知一只猪存钱罐空的时候的重量.现在的重量,已知若干种钱的重量和价值,猪里面装着若干钱若干份,求猪中的钱的价值最小值. 题解: DP,完全背包. g[j]表示组成重量j的最小花费 g[j]=min(g[j],g[j-w[i]]+v[i]) 完全背包物品可以多次使用,所以j的循环要正着来. 代码: #include<cstdio> #include<cmath> #include<iostream> #include<cstring…
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24132 Accepted: 8446 Description A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash amount. The machin…
Milking Grid POJ - 2185 最小覆盖子串: 最小覆盖子串(串尾多一小段时,用前缀覆盖)长度为n-next[n](n-pre[n]),n为串长. 当n%(n-next[n])==0时,有最小循环节(就是最小覆盖子串). 快照: 我对KMP的一些理解(lyp点拨的):pre[i](或next[i])的实质是串str[1..i]的最长且小于i的“相等前.后缀”分别为str[1..pre[i]](前缀)与str[(i-pre[i]+1)..i](后缀),通俗讲就是:使str[1..i…
题目链接:http://poj.org/problem?id=3616 有头牛产奶n小时(n<=1000000),但必须在m个时间段内取奶,给定每个时间段的起始时间和结束时间以及取奶质量 且两次取奶之间须间隔r-1个小时,求最大取奶质量 也就是说r = 2时 3分结束取奶,至少在5分才能取. 按照时间排序,dp[i]表示i时段的最大产奶量 //#pragma comment(linker, "/STACK:102400000, 102400000") #include <a…