poj 1949 Chores 最长路
求出最长路.....
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = 1e6+;
int head[maxn], dis[], num, val[];
struct node
{
int to, nextt, c;
}e[maxn];
void add(int u, int v, int c) {
e[num].to = v;
e[num].nextt = head[u];
e[num].c = c;
head[u] = num++;
}
void init() {
mem1(dis);
mem1(head);
num = ;
}
int dfs(int u) {
if(~dis[u])
return dis[u];
int ret = val[u], ans = ;
for(int i = head[u]; ~i; i = e[i].nextt) {
int v = e[i].to;
ans = max(ans, dfs(v));
}
return dis[u] = ans+ret;
}
int main()
{
int n, x, y;
while(cin>>n) {
init();
for(int i = ; i<=n; i++) {
scanf("%d", &val[i]);
scanf("%d", &x);
while(x--) {
scanf("%d", &y);
add(y, i, val[i]);
}
}
for(int i = ; i<=n; i++) {
if(dis[i]==-) {
dis[i] = dfs(i);
}
}
int ans = ;
for(int i = ; i<=n; i++) {
ans = max(ans, dis[i]);
}
printf("%d\n", ans);
}
return ;
}
poj 1949 Chores 最长路的更多相关文章
- POJ 1949 Chores(DAG上的最长路 , DP)
题意: 给定n项任务, 每项任务的完成用时t和完成每项任务前需要的k项任务, 求把所有任务完成的最短时间,有当前时间多项任务都可完成, 那么可以同时进行. 分析: 这题关键就是每项任务都会有先决条件, ...
- POJ 1949 Chores (很难想到的dp)
传送门: http://poj.org/problem?id=1949 Chores Time Limit: 3000MS Memory Limit: 30000K Total Submissio ...
- poj 2253 Frogger (最长路中的最短路)
链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...
- POJ 1949 Chores
Farmer John's family pitches in with the chores during milking, doing all the chores as quickly as p ...
- POJ 2472 106 miles to Chicago(Dijstra变形——史上最坑的最长路问题)
题目链接 :http://poj.org/problem?id=2472 Description In the movie "Blues Brothers", the orphan ...
- poj 3592 Instantaneous Transference 缩点+最长路
题目链接 给一个n*m的图, 从0, 0这个点开始走,只能向右和向下. 图中有的格子有值, 求能获得的最大值. 其中有些格子可以传送到另外的格子, 有些格子不可以走. 将图中的每一个格子都看成一个点, ...
- POJ.1752.Advertisement(差分约束 最长路SPFA)
题目链接 \(Description\) 有\(n\)个人在一条直线上跑步,每个人的起点 \(Si\).终点 \(Ei\) 已知:每个点可以放一个广告牌,一个人\(i\)能看到的广告牌数量为 \(Ei ...
- poj 1932 XYZZY(spfa最长路+判断正环+floyd求传递闭包)
XYZZY Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4154 Accepted: 1185 Description ...
- POJ 3126 --Father Christmas flymouse【scc缩点构图 && SPFA求最长路】
Father Christmas flymouse Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 3007 Accep ...
随机推荐
- SQL Server数据库--》top关键字,order by排序,distinct去除重复记录,sql聚合函数,模糊查询,通配符,空值处理。。。。
top关键字:写在select后面 字段的前面 比如你要显示查询的前5条记录,如下所示: select top 5 * from Student 一般情况下,top是和order by连用的 orde ...
- linux下不重启加硬盘
linux下热加载磁盘 临时给虚拟机加了一块硬盘,增加后懒得重启,于是看了看热加载 [root@centos5 ~]# cat /proc/scsi/scsi Attached devices: Ho ...
- 并发编程: c++11 thread(Func, Args...)利用类成员函数创建线程
c++11是VS2012后支持的新标准,为并发编程提供了方便的std::thread. 使用示例: #include <thread> void thread_func(int arg1, ...
- ?super T 和? extends T区别
Java 泛型 关键字说明 ? 通配符类型 <? extends T> 表示类型的上界,表示参数化类型的可能是T 或是 T的子类 <? super T> 表示类型下界(Java ...
- Constructor JavaScript构造器模式。
构造器模式 : Constructor模式中, 通过在构造器前面加 new 关键字, 告诉JavaScript 像使用构造器一样实例化一个新对象,并且对象成员由该函数定义. 构造器内, 使用this ...
- Linux学习之常用技巧
▌基础 学习 Bash .你可以man bash来看看bash的东西,并不复杂也并不长.你用别的shell也行,但是bash是很强大的并且也是系统默认的.(学习zsh或tsch只会让你在很多情况下受到 ...
- PHP中字符串补齐为定长
方法一 for ($i=0; $i<100; $i++) { $index = sprintf('%04d', $i); echo $index.'<br />'; } 方法二 fo ...
- UIWebViewでローカルにあるHTMLを表示する&iOS6からtextAlignmentで指定する値が変更になった
[objective-c]UIWebViewでローカルにあるHTMLを表示する xcode内にHTMLを格納して.そのHTMLをWebViewで表示する方法です. // UIWebViewの初期化UI ...
- GMTED2010 高程数据下载
http://topotools.cr.usgs.gov/GMTED_viewer/viewer.htm
- QCA4002/QCA4004 为主流家电和消费电子产品推出低功耗Wi-Fi平台
美国高通公司日前宣布,其子公司高通创锐讯推出全新芯片系列,这是低功耗Wi-Fi解决方案系列的一部分,可连接组成物联网的各种设备.QCA4002和QCA4004网络平台在芯片上纳入IP堆栈及完整的网络服 ...