POJ 1036 Gangsters
来源:互联网 发布:js无限下拉页面瀑布流 编辑:程序博客网 时间:2024/06/12 01:08
Gangsters
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 13041 Accepted: 3728
Description
N gangsters are going to a restaurant. The i-th gangster comes at the time Ti and has the prosperity Pi. The door of the restaurant has K+1 states of openness expressed by the integers in the range [0, K]. The state of openness can change by one in one unit of time; i.e. it either opens by one, closes by one or remains the same. At the initial moment of time the door is closed (state 0). The i-th gangster enters the restaurant only if the door is opened specially for him, i.e. when the state of openness coincides with his stoutness Si. If at the moment of time when the gangster comes to the restaurant the state of openness is not equal to his stoutness, then the gangster goes away and never returns.
The restaurant works in the interval of time [0, T].
The goal is to gather the gangsters with the maximal total prosperity in the restaurant by opening and closing the door appropriately.
Input
?The first line of the input file contains the values N, K, and T, separated by spaces. (1 <= N <= 100 ,1 <= K <= 100 ,0 <= T <= 30000 )
?The second line of the input file contains the moments of time when gangsters come to the restaurant T1, T2, …, TN, separated by spaces. ( 0 <= Ti <= T for i = 1, 2, …, N)
?The third line of the input file contains the values of the prosperity of gangsters P1, P2, …, PN, separated by spaces. ( 0 <= Pi <= 300 for i = 1, 2, …, N)
?The forth line of the input file contains the values of the stoutness of gangsters S1, S2, …, SN, separated by spaces. ( 1 <= Si <= K for i = 1, 2, …, N)
All values in the input file are integers.
Output
Print to the output file the single integer ?the maximal sum of prosperity of gangsters in the restaurant. In case when no gangster can enter the restaurant the output should be 0.
Sample Input
4 10 20
10 16 8 16
10 11 15 1
10 7 1 8
Sample Output
26
Thinking: 三天来的第一道题,果然食言了。晚上一点睡,痘痘长一对。言归正传,这道题还是比较常规的,可惜在看openness of the door coincides with the stousness 这点的时候晕了 ,纠结了好久。
dp[i]: 表示第i个人进去后的最大P值
可得地推关系式 dp[i] = max(dp[i], dp[j]+line[i].p);
#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespace std;int N, K, T;const int maxn = 105;struct node{ int t, p, s; bool operator < (const node& n) const{ if(n.t != t){ return t < n.t; }else{ return s < n.s; } }}line[maxn];int dp[maxn];void solve(){ memset(dp, 0, sizeof(dp)); sort(line+1, line+N+1); for(int i = 1; i <= N; i++){ for(int j = 0; j < i; j++){ if(dp[j] >= line[j].p){//这里一定要判断第J个人进去了 if(abs(line[i].s - line[j].s) <= line[i].t - line[j].t){ dp[i] = max(dp[i], dp[j] + line[i].p); } } } } int ans = 0; for(int i = 1; i <= N; i++) ans = max(ans, dp[i]); printf("%d\n", ans);}int main(){ while(scanf("%d%d%d", &N, &K, &T) == 3){ for(int i = 1; i <= N; i++) scanf("%d", &line[i].t); for(int i = 1; i <= N; i++) scanf("%d", &line[i].p); for(int i = 1; i <= N; i++) scanf("%d", &line[i].s); solve(); } return 0;}
- poj 1036 Gangsters
- poj 1036 Gangsters
- poj 1036 Gangsters
- POJ 1036 Gangsters
- POJ 1036 Gangsters
- POJ 1036 Gangsters (DP)
- POJ 1036 Gangsters
- POJ 1036 Gangsters
- POJ 1036 Gangsters 题解
- POJ 1036 Gangsters
- poj 1036 Gangsters lis
- POJ 1036 Gangsters 笔记
- POJ 1036 Gangsters
- POJ 1036 Gangsters DP 多解
- poj 1036 Gangsters(DP)
- poj 1036 Gangsters (简单dp)
- POJ 1036 Gangsters 水dp。。
- POJ 1036 Gangsters(DP)
- MATLAB 使用(三)控制双精度浮点数的显示格式
- 不能打开Eclipse MarketPlace
- 阿里云全球第二批MVP 祁宁专访
- NodeList nodelist 方法不存在错误 nodelist.item(0).getTextContent()
- 从Facebook的React框架事件学习一下开源协议
- POJ 1036 Gangsters
- 三级导航
- 学习日记-ajax异步转同步
- Beginning—Learn to use Markdown
- bind() to 0.0.0.0:8123 failed
- 二叉树 c 实现
- 同步锁
- A/B HDU1576
- 有用过PHP SPL的吗,不知道这主要用来干嘛