POJ 1036 Gangsters 题解
来源:互联网 发布:比价神器 软件下载 编辑:程序博客网 时间:2024/05/16 13:41
题意:
给出N个客人,每个客人到达饭店的时间以及他的prosperity和stoutness,饭店每分钟的stoutness要么+1,-1或者不变。每个客人进饭店后,饭店得到prosperity值,求最大的prosperity之和。
题解:
首先要是a[i].time>=a[i].stoutness,则i是可以进去的,则先初始化为a[i].p,否则为不可达状态-1;
然后要是转移方程:
if(abs(people[i].strong-people[j].strong)<=people[i].time-people[j].time) dp[i]=dp[i]>(dp[j]+people[i].value)?dp[i]:(dp[j]+people[i].value);
AC的代码:
#include<cstdio>#include<algorithm>using namespace std;struct P { int time,value,strong;};P people[105];int dp[105];int cmp(P a,P b) { return a.time<b.time;}int abs(int a) { return a>0?a:-a;}int main() { int N,K,T,i,j; while(~scanf("%d%d%d",&N,&K,&T)) { for(i=0; i<N; i++) scanf("%d",&people[i].time); for(i=0; i<N; i++) scanf("%d",&people[i].value); for(i=0; i<N; i++) scanf("%d",&people[i].strong); sort(people,people+N,cmp); for(i=0; i<N; i++) { if(people[i].time>=people[i].strong)dp[i]=people[i].value; else { dp[i]=-1; continue; } for(j=0; j<i; j++) { if(abs(people[i].strong-people[j].strong)<=people[i].time-people[j].time) dp[i]=dp[i]>(dp[j]+people[i].value)?dp[i]:(dp[j]+people[i].value); } } int ans=0; for(i=0; i<N; i++) ans=ans>dp[i]?ans:dp[i]; printf("%d\n",ans); } return 0;}
WA代码:
不知道为何WA。
#include<stdio.h>#include<algorithm>#include<math.h>using namespace std;struct Node{ int t; int p; int s;}a[109];int dp[109];bool cmp(Node aa,Node bb){ aa.t<bb.t;}int abs(int a) { return a>0?a:-a;}int main(){ int N,K,T; while(~scanf("%d %d %d",&N,&K,&T)){ for(int i=0;i<N;i++){ scanf("%d",&a[i].t); } for(int i=0;i<N;i++){ scanf("%d",&a[i].p); } for(int i=0;i<N;i++){ scanf("%d",&a[i].s); } sort(a,a+N,cmp); for(int i=0;i<N;i++) dp[i]=-1; for(int i=0;i<N;i++){ if(a[i].t>=a[i].s){ dp[i]=a[i].p; } } int ans=0; for(int i=0;i<N;i++){ if(a[i].t>=a[i].s){ dp[i]=a[i].p; }else { dp[i]=-1; continue; } for(int j=0;j<i;j++){ if(dp[j]==-1) continue; if((a[i].t-a[j].t)>=abs(a[i].s-a[j].s)) dp[i]=max(dp[i],dp[j]+a[i].p); } if(ans<dp[i]) ans=dp[i]; } printf("%d\n",ans); }return 0;}
0 0
- POJ 1036 Gangsters 题解
- 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 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)
- FirstWindow
- 细谈select函数(C语言)
- (12) 初学cocos2dx lua
- Java 中枚举类型的使用
- hdu 4778 Gems Fight!
- POJ 1036 Gangsters 题解
- QTP 自定义方法将IE最大化最小化
- ArcObjects帮助文档翻译--释放COM对象 Releasing COM references
- Cookie和Session的了解
- Android开发给TextView添加点击事件
- 渲染到纹理(转载)
- 分享一些爱情名句
- BFS、双向BFS和A*
- 第12周项目1 阅读程序(整型变量)