当前位置:网站首页>家庭琐事问题
家庭琐事问题
2022-07-27 10:04:00 【chengqiuming】
一 原问题链接
Chores - POJ 1949 - Virtual Judgehttps://vjudge.net/problem/POJ-1949
二 输入与输出
1 输入
第1行包含一个整数 N。第 2 ~ N+1 行描述每个家务,第 2 行包含家务1;第 3 行包含家务2,以此类推。每行都包含完成家务的时间、先决条件的数量 Pi 和 Pi 个先决条件。
2 输出
单行输出完成所有家务所需的最少时间。
三 输入与输出样例
1 输入
7
5 0
1 1 1
3 1 2
6 1 1
1 2 2 4
8 2 2 4
4 3 3 5 6
2 输出
23
四 分析和设计
1 拓扑图

2 分析
家务 1 在时间0开始,在时间 5 结束;
家务 2 在时间0开始,在时间 6 结束;
家务 3 在时间0开始,在时间 9 结束;
家务 4 在时间0开始,在时间 11 结束;
家务 5 在时间0开始,在时间 12 结束;
家务 6 在时间0开始,在时间 19 结束;
家务 7 在时间0开始,在时间 23 结束;
本问题的关键在于,家务 k 只能以家务 1~k-1 作为先决条件。也就是说,输入第 K 个家务时,它的先决条件均已确定什么时间结束。因此在输入过程中直接求最长距离即可。如果没有先决条件的限制,则不可以这样计算。
五 代码
package graph.poj1949;
import java.util.Scanner;
public class POJ1949 {
static final int maxn = 10010;
static int d[] = new int[maxn];
static int n;
public static void main(String[] args) {
int ans = 0, w, num, y;
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
for (int i = 1; i <= n; i++) {
w = scanner.nextInt();
num = scanner.nextInt();
d[i] = w;
for (int j = 1; j <= num; j++) {
y = scanner.nextInt();
d[i] = Math.max(d[i], d[y] + w);
}
ans = Math.max(ans, d[i]);
}
System.out.println(ans);
}
}六 测试
绿色为输入,白色为输出

边栏推荐
- Matlab create text cloud
- 【英雄哥六月集训】第 28天: 动态规划
- window平台下本地连接远程服务器数据库(一)
- ctf (hardrce)
- gyp ERR! configure error. gyp ERR! stack Error: gyp failed with exit code: 1
- warning package.json: No license field报错
- Two architectures of ETL (ETL architecture and ELT Architecture)
- Oracle 11g manual memory management
- 程序的翻译和执行,从编辑、预处理、编译、汇编、链接到执行
- Uninstall cuda11.1
猜你喜欢

How to turn off the application of computer self startup

多点双向重发布和路由策略

Samba server

线代004

【Liunx】MariaDB/MySQL定时全量备份脚本及数据恢复
![Shell function, system function, basename [string / pathname] [suffix] can be understood as taking the file name in the path, dirname file absolute path, and user-defined function](/img/3d/d7276d2010f1d77a3bd572cc66eced.png)
Shell function, system function, basename [string / pathname] [suffix] can be understood as taking the file name in the path, dirname file absolute path, and user-defined function

Robotframework+eclispe environment installation
![[Flink] Flink builds clusters in standalone mode](/img/5b/e566fdd2792b5cda7d37d308ee32e2.png)
[Flink] Flink builds clusters in standalone mode

samba服务器

女粉想要找男朋友,竟是为了...
随机推荐
Discussion on a problem
wind10配置adb命令
Local connection to remote server database under Windows platform (I)
[brother hero June training] day 28: dynamic planning
Matlab low-level source code realizes the median filtering of the image (used to eliminate some miscellaneous points on the image)
Redis数据结构分析(二)
Oracle查看硬解析
数学推理题:张王李赵陈五对夫妇聚会,见面握手
[Select] how to write PHP code perfectly?
【英雄哥六月集训】第 26天: 并查集
Matlab/Simulink求解微分方程样例分享
File upload vulnerability related
A brief introduction to R language pipeline symbols (% >%) and placeholders (.)
R语言管道符(%>%)及占位(.)的简单介绍
【Liunx】安装Redis
Program translation and execution, from editing, preprocessing, compilation, assembly, linking to execution
Establishment of NFS server
Echats关系图les-miserables的图表详细解析(和弦图)
Matlab create text cloud
【Flink】Flink进行Standalone模式的集群搭建