uva 672(dp)
来源:互联网 发布:java正则匹配汉字 编辑:程序博客网 时间:2024/04/28 08:20
题意:有n个歹徒要进入一家餐厅,餐厅有一扇门,门初始大小是0,门会每秒增大1或减小1或不变,但范围在[0,k],然后每个歹徒都有到达餐厅的时间ti,每个人有一个财富值pi和自己的体型值si,只有歹徒到达餐厅时门的大小和si相等时他才能进入餐厅,餐厅就会增加pi,问餐厅最多增加的总pi值是多少。
题解:f[i]表示前i个人能让餐厅增加的总Pi值是多少,先把歹徒到餐厅的时间排序,然后对比歹徒间到达时间差和体型差来判断如果前者进入后者是否也能进入,f[i] = max(f[i], f[j] + pi)。
#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>using namespace std;const int N = 105;struct Gan { int t, p, s;}gan[N];int n, K, T, f[N];bool cmp(Gan a, Gan b) { return a.t < b.t;}int main() { int cas; scanf("%d", &cas); while (cas--) { scanf("%d%d%d", &n, &K, &T); for (int i = 1; i <= n; i++) scanf("%d", &gan[i].t); for (int i = 1; i <= n; i++) scanf("%d", &gan[i].p); for (int i = 1; i <= n; i++) scanf("%d", &gan[i].s); sort(gan + 1, gan + 1 + n, cmp); memset(f, -1, sizeof(f)); f[0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < i; j++) { if (f[j] != -1) { //如果j不能进去就不能通过他判断i能否进入 int temp = gan[i].t - gan[j].t; int temp2 = fabs(gan[i].s - gan[j].s); if (temp >= temp2) f[i] = max(f[i], f[j] + gan[i].p); } } } int res = 0; for (int i = 1; i <= n; i++) res = max(res, f[i]); printf("%d\n", res); if (cas) printf("\n"); } return 0;}
0 0
- uva 672 Gangsters( dp )
- UVA 672 - Gangsters(dp)
- uva 672 - Gangsters(dp)
- uva 672(dp)
- uva 672 dp
- UVA DP 入门专题
- uva 1424 简单DP
- uva 10192 DP
- UVA dp题目汇总
- UVa 4256 - Salesmen dp
- UVa 10271 - Chopsticks dp
- UVA 1424 - Salesmen (dp)
- UVA 10271 Chopsticks(dp)
- uva 10271 Chopsticks(dp)
- UVA 11584 DP水题
- UVA 1424 DP水题
- UVA 10534 DP+LIS
- UVA 11552 DP水题
- [Android]自定义dialog
- NYOJ266 字符串逆序输出
- codevs1031
- 【JavaScript 13—应用总结】:锁屏遮罩
- STL map的基本成员函数
- uva 672(dp)
- android开发工程师三大历程
- 设计模式_抽象工厂模式
- 2015年7月17日 午後3時のニュース NHK新闻稿
- codeforces558C Amr and Chemistry
- 算法导论,最优钢条切分
- (算法入门)基本图论-广度优先搜索之JAVA实现
- codevs1032
- android.content.res.Resources$NotFoundException: String resource ID #0x1异常