POJ 1036 Gangsters
来源:互联网 发布:幸亏没生在古代 知乎 编辑:程序博客网 时间:2024/05/18 12:39
http://poj.org/problem?id=1036
先按时间排序,然后dp
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cstdlib>#include <cmath>#define N 110using namespace std;struct num{ int time,p,s;}a[N];int dp[N][N];bool cmp(num p1,num p2){ return p1.time<p2.time;}int main(){ int n,k,t; while(scanf("%d %d %d",&n,&k,&t)!=EOF) { for(int i=1;i<=n;i++) { scanf("%d",&a[i].time); } for(int i=1;i<=n;i++) { scanf("%d",&a[i].p); } for(int i=1;i<=n;i++) { scanf("%d",&a[i].s); } sort(a+1,a+n+1,cmp); memset(dp,-1,sizeof(dp)); dp[0][0] = 0; a[0].time = 0; a[0].p = 0; a[0].s = 0; for(int i=1;i<=n;i++) { for(int j=0;j<=k;j++) { if(dp[i-1][j]==-1) { continue; } dp[i][j] = max(dp[i][j],dp[i-1][j]); for(int u=0;u<=k;u++) { if(abs(j-u)<=abs(a[i].time-a[i-1].time)&&u==a[i].s) { dp[i][u] = max(dp[i][u],dp[i-1][j]+a[i].p); }else if(abs(j-u)<=abs(a[i].time-a[i-1].time)) { dp[i][u] = max(dp[i][u],dp[i-1][j]); } } } } int ans = 0; for(int i=0;i<=k;i++) { ans = max(dp[n][i],ans); } 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 (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)
- 程序设计实习MOOC/第十三周编程作业/C:UNIMODAL PALINDROMIC DECOMPOSITIONS(Greater New York 2002)
- 集合框架—Set
- [AC自动机+dp+矩阵快速幂] poj 2778 DNA Sequence
- 聚簇索引、非聚簇索引、覆盖索引
- 完备匹配下的最大权匹配
- POJ 1036 Gangsters
- week 13 练习一
- ajax 导Excel的不能导
- 开源EDA工具
- uva 11249 - Game
- 黑马程序员_Java基础_集合框架成员Collection
- Oracle数据库,实例,表空间,用户,表之间的关系简析
- Leetcode中括号题
- 【DP|混合背包】POJ-3260 The Fewest Coins