poj 1821 动态规划
思路:每次枚举每个工人的右边界j,维护最优的左边界k。那么dp[j]=max(dp[j],dp[k]+(j-k)*w[i].p);
对于每个工人的初值k=w[i].s-1;
令x=j-w[i].l,如果(k-x)*w[i].p>dp[k]-dp[x],则k=x。
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pb push_back
#define mp make_pair
#define Maxn 170010
#define Maxm 200010
#define LL __int64
#define Abs(x) ((x)>0?(x):(-x))
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
#define inf 100000
#define lowbit(x) (x&(-x))
#define clr(x,y) memset(x,y,sizeof(x))
#define Mod 1000000007
using namespace std;
int dp[Maxn];
struct Workers{
int s,p,l;
int operator<(const Workers &temp) const{
return s<temp.s;
}
}w[];
int main()
{
int n,i,j,K,k,x;
//freopen("aa.txt","r",stdin);
while(scanf("%d%d",&n,&K)!=EOF){
clr(dp,);
for(i=;i<=K;i++){
scanf("%d%d%d",&w[i].l,&w[i].p,&w[i].s);
}
sort(w+,w++K);
int ed,st,temp;
for(i=;i<=K;i++){
int ed=w[i].s+w[i].l-;
k=w[i].s-;
for(j=ed;j>=w[i].s;j--){
x=j-w[i].l;
x=max(x,);
if((k-x)*w[i].p>dp[k]-dp[x])
k=x;
dp[j]=max(dp[j],dp[k]+(j-k)*w[i].p);
}
for(j=;j<=n;j++)
dp[j]=max(dp[j],dp[j-]);
}
printf("%d\n",dp[n]);
}
return ;
}
poj 1821 动态规划的更多相关文章
- poj 1821 Fence 单调队列优化dp
/* poj 1821 n*n*m 暴力*/ #include<iostream> #include<cstdio> #include<cstring> #incl ...
- poj 1821 Fence(单调队列优化DP)
poj 1821 Fence \(solution:\) 这道题因为每一个粉刷的人都有一块"必刷的木板",所以可以预见我们的最终方案里的粉刷匠一定是按其必刷的木板的顺序排列的.这就 ...
- poj 1821 Fence(单调队列)
题目链接:http://poj.org/problem?id=1821 题目分析来自:http://blog.csdn.net/tmeteorj/article/details/8684453 连续的 ...
- nyoj 17-单调递增最长子序列 && poj 2533(动态规划,演算法)
17-单调递增最长子序列 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:21 submit:49 题目描述: 求一个字符串的最长递增子序列的长度 如 ...
- poj 3034 动态规划
思路:这是一道坑爹的动态规划,思路很容易想到,就是细节. 用dp[t][i][j],表示在第t时间,锤子停在(i,j)位置能获得的最大数量.那么只要找到一个点转移到(i,j)收益最大即可. #incl ...
- poj 2498 动态规划
思路:简单动态规划 #include<map> #include<set> #include<cmath> #include<queue> #inclu ...
- poj 2287 动态规划
用贪心简单证明之后就是一个从两头取的动态规划 #include <iostream> #include <cstring> #include <cstdio> #i ...
- POJ 1821 Fence
Fence Time Limit: 1000ms Memory Limit: 30000KB This problem will be judged on PKU. Original ID: 1821 ...
- POJ 2533 动态规划入门 (LIS)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 42914 Accepte ...
随机推荐
- sql reiserror 输出错误
其语法如下: RAISERROR ( { msg_id | msg_str | @local_variable } { ,severity ,state } ...
- EF小节
EF学习笔记——生成自定义实体类 http://blog.csdn.net/leftfist/article/details/24889819 --工具: 1.entity developer 2.D ...
- TL-WR703 USB不稳定/当前的总结
http://see.sl088.com/wiki/WR703_USB%E4%B8%8D%E7%A8%B3%E5%AE%9A/%E5%BD%93%E5%89%8D%E7%9A%84%E6%80%BB% ...
- ThinkPHP模板(一)
如何关闭ThinkPHP的模板缓存 ThinkPHP的模板缓存是无奈关闭的,因为内置的模板引擎是一个编译型的模板引擎,必须经过编译后生成一个可执行的缓存文件才能被执行.但是可以设置缓存的有效期,例如设 ...
- .Net连接到SAP【转载】
刚开始接触SAP了,感觉很陌生,清一色的TCode,不过里面的功能确实强大,不得不佩服啊,之前我一直是搞WinForm和WebForm的,现在能够接触到SAP那我还是想多学习一下,看了一下ABAP的语 ...
- IOS 7 Study - Implementing Navigation with UINavigationController
ProblemYou would like to allow your users to move from one view controller to the other witha smooth ...
- 为C# Windows服务添加安装程序
最近一直在搞Windows服务,也有了不少经验,感觉权限方面确定比一般程序要受限很多,但方便性也很多.像后台运行不阻塞系统,不用用户登录之类.哈哈,扯远了,今天讲一下那个怎么给Windows服务做个安 ...
- Java学习笔记(4)——JavaSE
一.HashMap HashMap以键值对的形式存储对象,关键字Key是唯一的,不重复的 1,key可以是任何对象,Value可以任何对象 2,重复的key算一个,重复添加是替换操作(会覆盖原来的元素 ...
- 使用sqlite的命令操作
一: 首先进入到D:\java\android\android-sdk\platform-tools文件夹里面 二:使用adb shell进入shell命令方式行(注意要想进入shell里面的操作 ...
- 关于pushState
window.pushState({}, "title", "/index.html");---------------->改变URL的值,但是并不刷新 ...