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 ...
随机推荐
- 6 种CSS设置居中的方法
原文 Demos of each of the methods below by clicking here. Horizontal centering with css is rather easy ...
- Linux 禁用笔记本触摸板
1. 查看有什么设备 xinput list 输出: ⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST p ...
- Mes首检确认统计的存储过程
USE [ChiefmesNEW]GO/****** Object: StoredProcedure [dbo].[st_MES_RptInspectFirstCollect] Script Date ...
- 查找DOM
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 集成iscroll 下拉加载更多 jquery插件
一个插件总是经过了数月的沉淀,不断的改进而成的.最初只是为了做个向下滚动,自动加载的插件.随着需求和功能的改进,才有了今天的这个稍算完整的插件. 一.插件主功能: 1.下拉加载 2.页面滚动到底部自动 ...
- MySQL 索引优化 btree hash rtree
一.MySQL索引类型 mysql里目前只支持4种索引分别是:full-text,b-tree,hash,r-tree b-tree索引应该是mysql里最广泛的索引的了,除了archive基本所有的 ...
- hihocoder #1178 : 计数 暴力
#1178 : 计数 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/problemset/problem/1178 ...
- Android程序开发0基础教程(一)
程序猿学英语就上视觉英语网 Android程序开发0基础教程(一) 平台简单介绍 令人激动的Google手机操作系统平台-Android在2007年11月13日正式公布了,这是一个开放源码的操 ...
- python 中sys.stdout.write 和 print >> sys.stdout的区别(转)
下面应该可以解你的惑了: print >> sys.stdout的形式就是print的一种默认输出格式,等于print "%VALUE%" 看下面的代码的英文注释,是p ...
- 删除sqlserver2008登录记录
SQL Server Management Studio登陆窗口 清空这些多余的登陆名 删除SqlStudio.bin文件 WinXP: C:\Documents and Settings\用户文件夹 ...