POJ 1949Chores(树形dp)
来源:互联网 发布:shift js按键 编辑:程序博客网 时间:2024/05/22 01:38
想来想去不知道怎么用拓扑,然后dp过了。
树形dp挺简单的,就是父节点完成的时刻是该节点所有的子节点完成时刻中的最大值加上父节点完成需要的时间(注意一下时刻跟时间)。然后一次水过去了。
#pragma warning(disable:4996)#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int N = 10005;vector<int>g[N];int cnt[N], cost[N], n;int ok[N];void dfs(int u) {if (ok[u] != -1)return;if (cnt[u] == 0) {ok[u] = cost[u];return;}int tmp = 0;for (int i = 0; i < (int)g[u].size(); i++) {dfs(g[u][i]);tmp = max(tmp, ok[g[u][i]]);}ok[u] = tmp + cost[u];}int main() {//freopen("in.txt", "r", stdin);scanf("%d", &n);for (int i = 1; i <= n; i++) {int x;scanf("%d %d", cost + i, &x);cnt[i] = x;while (x--) {int v; scanf("%d", &v);g[i].push_back(v);}}int ans = 0;memset(ok, -1, sizeof ok);for (int i = n; i > 0; i--) {if (ok[i] == -1)dfs(i);ans = max(ans, ok[i]);}printf("%d\n", ans);return 0;}
0 0
- POJ 1949Chores(树形dp)
- POJ 1949 Chores(DP)
- (POJ 1949)Chores DAG简单DP
- POJ 1949 Chores(树状DP)
- [poj 1949]Chores 题解 [dp]
- (POJ DP1.1)POJ 1949 Chores(简单DP)
- poj 1949 Chores(基础题)
- poj 1949 Chores
- poj 1949 Chores
- POJ 1949 Chores
- poj 1949 Chores
- ACM POJ 1949 Chores
- POJ 1949 Chores
- 【poj 1949】Chores
- poj 1949 Chores
- POJ 1949 Chores 笔记
- POJ 1949 Chores 动态规划
- poj 1949——Chores
- mknod命令 linux
- win7 QQ自动远程协助 提示关闭了远程桌面
- zTree异步加载并初始化树时全部展开
- 使用LaTeX轻松撰写精美个人简历
- UITextView 用法小结
- POJ 1949Chores(树形dp)
- Java简单万年历
- java 杂记
- 数组和lookup函数
- effective c++:了解c++默默编写并调用了哪些函数
- 9月8日 笔记
- [笔记][Java7并发编程实战手册]5.Fork\Join(Java1.7新特性)框架
- Linux战地日记——grep和sort命令
- hadoop-2.5.2伪分布环境搭建