称号:生命是非常多的选择。现在给你一些选择(0~n-1),和其他选项后,分支数每一次选择,选择共求。

分析:dp,图论。假设一个状态也许是选择的数量0一个是,代表死亡,计数的路径数将达到所有死亡可以去除。

用一个状态数组记录到达每一个选择的路径数,它等于能到达它的前驱节点的路径加和。

稀疏图,使用邻接表储存。初始是节点0的路径条数为1。代表出生。

说明:没有给数据范围略坑啊,RE一次。WA一次。╮(╯▽╰)╭。

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio> using namespace std; int sums[15000];
int deat[15000]; typedef struct tnode
{
int point;
tnode *next;
}node;
node* H[15000];
node E[150000];
int e_size = 0; void initial()
{
memset( H, 0, sizeof(H) );
memset( E, 0, sizeof(E) );
e_size = 0;
} void addedge( int a, int b )
{
E[e_size].point = b;
E[e_size].next = H[a];
H[a] = &E[e_size ++];
} int main()
{
int n,m,c,t = 1;
while ( ~scanf("%d",&n) ) {
if ( t ++ > 1 ) printf("\n");
initial();
memset( sums, 0, sizeof(sums) );
for ( int i = 0 ; i < n ; ++ i ) {
scanf("%d",&m);
for ( int j = 0 ; j < m ; ++ j ) {
scanf("%d",&c);
addedge( i, c );
}
if ( !m ) deat[i] = 1;
else deat[i] = 0;
} sums[0] = 1;
for ( int i = 0 ; i < n ; ++ i )
for ( node* p = H[i] ; p ; p = p->next )
sums[p->point] += sums[i];
int sum = 0;
for ( int i = 1 ; i < n ; ++ i )
if ( deat[i] )
sum += sums[i]; printf("%d\n",sum);
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

UVa 988 - Many Paths, One Destination的更多相关文章

  1. UVA 10564 十 Paths through the Hourglass

     Paths through the Hourglass Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & % ...

  2. UVA 10000 Longest Paths (SPFA算法,模板题)

    题意:给出源点和边,边权为1,让你求从源点出发的最长路径,求出路径长度和最后地点,若有多组,输出具有最小编号的最后地点. #include <iostream> #include < ...

  3. UVA 125 Numbering Paths

    题目大意:给定n条单向边,求图中任意两点的连通路径的数目.其中点是从0-输入中出现的最大的点. 可以用floyd-warshall算法或者dfs. for(int k = 0; k < n; k ...

  4. UVa 10564 DP Paths through the Hourglass

    从下往上DP,d(i, j, k)表示第(i, j)个格子走到底和为k的路径条数. 至于字典序最小,DP的时候记录一下路径就好. #include <cstdio> #include &l ...

  5. How an Event Enters a Cocoa Application

    How an Event Enters a Cocoa Application An event is a low-level record of a user action that is usua ...

  6. On-demand diverse path computation for limited visibility computer networks

    In one embodiment, a source device detects a packet flow that meets criteria for multi-path forwardi ...

  7. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  8. 01背包(类) UVA 10564 Paths through the Hourglass

    题目传送门 /* 01背包(类):dp[i][j][k] 表示从(i, j)出发的和为k的方案数,那么cnt = sum (dp[1][i][s]) 状态转移方程:dp[i][j][k] = dp[i ...

  9. LeetCode 1059. All Paths from Source Lead to Destination

    原题链接在这里:https://leetcode.com/problems/all-paths-from-source-lead-to-destination/ 题目: Given the edges ...

随机推荐

  1. 出现异常 child-&gt;m_pParent == 0

    在cocos2d-x中,能够用CCNode类 自己new一个节点(或是用CCnode::node().create()),当将它作为其它若干item(如button项.sprite项.image项)的 ...

  2. 第四章 Spring与JDBC的整合

    这里选择的是mysql数据库. 4.1引入aop.tx的命名空间 为了事务配置的需要,我们引入aop.tx的命名空间 <?xml version="1.0" encoding ...

  3. 如何使用git

    本文不是谈论git具体命令的技术文章. 原文地址:http://blog.csdn.net/ffb/article/details/11206067 我之前发了一条关于git中如何处理中文文件名的微博 ...

  4. Eclipse插件引入jar包的方法

    搞了两天,终于找到解决办法了.原来  Eclipse 插件项目引入外面的jar包不能用   build path---->add external jars的方法. 先说明两个概念:类加载器,O ...

  5. VS2010-win32下cocos2dx控制台打印的方法

    在xcode中  直接使用printf 或者 cout<<""<<endl;可以直接在控制台打印 但是在VS2010 却死活不好用   真郁闷 ------ ...

  6. Cocos2d-x 3.1.1 Lua实例-AccelerometerTest(重力加速计)

    Cocos2d-x 3.1.1 Lua实例-AccelerometerTest(重力加速计) 本篇博客介绍Cocos2d-x的第一个实例--重力加速计測试.效果图(注:这里无法模拟重力感应): --[ ...

  7. &lt;xliff:g&gt;标签

    摘要: 这是Android4.3Mms源代码中的strings.xml的一段代码: <!--Settings item desciption for integer auto-delete sm ...

  8. dedecms 文章列表和频道列表同时调用

    演示效果:http://www.mypf110.com/qcd/ <div class="changshi_wrap"> {dede:channelartlist ro ...

  9. 【VB/.NET】Converting VB6 to VB.NET 【Part II】【之四】

    第四部分 原文 DLLs, DAO, RDO, ADO, and AD.NET; the History of VB DBs In the early versions of VB, there we ...

  10. RGB與CIELAB色彩空間轉換

    原地址:http://cg2010studio.wordpress.com/2012/10/02/rgb與cielab色彩空間轉換/ 之前有研究CIE L*a*b*色彩空間,現在想更進一步探討RGB色 ...