称号:生命是非常多的选择。现在给你一些选择(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. HTML 页面载入 Flash 插件的几种方法

    前言 之所以写这篇文章,主要是由于组长给提的一个新的需求--使用浏览器调用电脑的摄像头,来实现即时拍照的功能.在网上查了非常多资料,由于这样那样的原因,终于选择了使用flash插件来调用pc的摄像头. ...

  2. cocos2dX 事件之触摸事件和触摸事件集合

    今天, 我们来学习cocos2dX里面的触摸事件与触摸事件合集, 如今的手机游戏交互基本上都是通过触摸交互的, 所以大家明确这节的重要性了吧, 本节篇幅比較大, 所以我就不扯闲话了 先来看看经常使用函 ...

  3. ThinkPhp学习13

    原文:ThinkPhp学习13 简单登录验证 创建Login类 <?php class LoginAction extends Action { function index(){ $this- ...

  4. LCS小结(O(∩_∩)O~吽吽)

    LCS!~如果你在百度上搜这个的话会出来”英雄联盟冠军联赛”,orz..但是今天要讲的LCS是最长公共子序列 ,"Longest Common Subsequence "not&q ...

  5. LINUX专题之操作系统字符集

    原创作品,出自 "深蓝的blog" 博客,欢迎转载.转载时请务必注明下面出处,否则追究版权法律责任. 深蓝的blog: http://blog.csdn.net/huangyanl ...

  6. 手机装linux系统

    第一步: 首先 , 你的手机需要获取root权限. 如果不知道如何获取, 可以到电脑上搜索一下安卓手机root教程. 不同品牌的手机root的方法不同. 也可以到机锋论坛上寻找root的具体方法. 第 ...

  7. 怎样在Linux下通过ldapsearch查询活动文件夹的内容

    从Win2000開始.微软抛弃NT域而採用活动文件夹来管理Windows域.而活动文件夹就是微软基于遵守LDAP协议的文件夹服务.假设用扫描器扫描的话能够发现活动文件夹的389port是打开的.并且微 ...

  8. Creating Contextual Menus创建上下文菜单

    A contextual menu offers actions that affect a specific item or context frame in the UI. You can pro ...

  9. ElasticSearch+Kibana 索引操作

    ElasticSearch+Kibana 索引操作 一 前言 ElasticiSearch 简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引 ...

  10. Java使用反射机制优化工厂方法

    我先举个例子,有一个接口People,这个接口有一个方法: package com.wjy.reflect; public interface People { public abstract voi ...