UVa 10926 - How Many Dependencies?
来源:互联网 发布:如何做淘宝客服兼职 编辑:程序博客网 时间:2024/05/17 01:09
题目:给你一下任务以及这些任务的依赖关系,求有最长依赖关系链的任务。
分析:搜索。可以利用dfs或者记忆化搜索。
(因为没有环是树状结构,所以每个根计算时的解就是最终结果,不会被更新)。
说明:每次要清空标记的数组。
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <cmath>using namespace std;int maps[101][101];int used[101];int dfs(int s, int n){if (used[s]) return used[s];int Max = 0;for (int i = 1 ; i <= n ; ++ i)if (maps[s][i]) Max = max(Max, dfs(i, n)+1);return used[s] = Max;}int main(){int n,m,p;while (~scanf("%d",&n) && n) {memset(maps, 0, sizeof(maps));memset(used, 0, sizeof(used));for (int i = 1 ; i <= n ; ++ i) {scanf("%d",&m);for (int j = 1 ; j <= m ; ++ j) {scanf("%d",&p);maps[i][p] = 1;}maps[0][i] = 1;}dfs(0, n);int space = 1;for (int i = 2 ; i <= n ; ++ i) if (used[space] < used[i])space = i;printf("%d\n",space);} return 0;}
0 0
- UVa 10926 - How Many Dependencies?
- UVA 10926 How Many Dependencies?
- UVA 10926--How Many Dependencies?
- dfs-uva 10926 How Many Dependencies
- How Many Calls? UVA
- Uva 10303 How Many Trees?
- uva 10183 how many fibs
- uva 10183 How Many Fibs
- UVa 696 - How Many Knights
- UVa 10183 - How Many Fibs?
- UVA 10183 How Many Fibs?
- UVA 10518 How Many Calls?
- UVA 10303 How Many Trees?
- UVa 10183 - How Many Fibs?
- UVa 10183 - How Many Fibs?
- UVA 10183 How Many Fibs?
- UVA 10303 How Many Trees?
- UVA 10518 How Many Calls?
- LaTeX新人教程,30分钟从完全陌生到基本入门
- 一个天气App案例 -- ReactiveCocoa
- 自定义的数字软键盘
- 程序员装机必备的十款软件
- @Mock, @Spy, @Captor and @InjectMocks
- UVa 10926 - How Many Dependencies?
- 借助Xutils实现多线程下载
- CSS学习经验
- Too many content provider operations between yield points解决方法
- 可勾选的ExpandableListView
- 兔子-cvc-complex-type.2.3: Element 'web-app' cannot have character [children], because the type's cont
- android NFC 读写
- Android onInterceptTouchEvent setOnChangedListener onTouchEvent
- ASP.NET MVC 4專案4.5 Framework轉4.0