UVa 988 - Many Paths, One Destination
称号:生命是非常多的选择。现在给你一些选择(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的更多相关文章
- UVA 10564 十 Paths through the Hourglass
Paths through the Hourglass Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & % ...
- UVA 10000 Longest Paths (SPFA算法,模板题)
题意:给出源点和边,边权为1,让你求从源点出发的最长路径,求出路径长度和最后地点,若有多组,输出具有最小编号的最后地点. #include <iostream> #include < ...
- UVA 125 Numbering Paths
题目大意:给定n条单向边,求图中任意两点的连通路径的数目.其中点是从0-输入中出现的最大的点. 可以用floyd-warshall算法或者dfs. for(int k = 0; k < n; k ...
- UVa 10564 DP Paths through the Hourglass
从下往上DP,d(i, j, k)表示第(i, j)个格子走到底和为k的路径条数. 至于字典序最小,DP的时候记录一下路径就好. #include <cstdio> #include &l ...
- 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 ...
- 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 ...
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- 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 ...
- LeetCode 1059. All Paths from Source Lead to Destination
原题链接在这里:https://leetcode.com/problems/all-paths-from-source-lead-to-destination/ 题目: Given the edges ...
随机推荐
- POJ1422 Air Raid 【DAG最小路径覆盖】
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6763 Accepted: 4034 Descript ...
- Oracle百问百答(一)
Oracle百问百答(一) 01.如何查看oracle的版本信息? 02.如何查看系统被锁的事务信息? 03.怎么获取有哪些用户在使用数据库? 04. 数据表中的字段最大数是多少? 表或视图中的最大列 ...
- 自学PHP 环境搭建
自学PHP之环境搭建 一..首先 安装 phpStudy2013.exe 程序集成包 安装完可能端口被占用 需要手动设置 然后打开http://localhost:8080/phpMyAdmin/ ...
- Swift 编程语言新手教程
今天在网上看到一篇很好的教程,分享给大家 原文地址:http://gashero.iteye.com/blog/2075324 文件夹 1 简单介绍 2 Swift入门 3 简单值 4 ...
- SLB 权重问题
<pre name="code" class="html">一般配置SLB的时候有个权重0到100,是如何选择数值的? 权重需要您根据后端机器的配置 ...
- mysql 高可用方案MHA介绍
概述 MHA是一位日本MySQL大牛用Perl写的一套MySQL故障切换方案,来保证数据库系统的高可用.在宕机的时间内(通常10—30秒内),完成故障切换,部署MHA,可避免主从一致性问题,节约购买新 ...
- linux使用进阶(一)
本文依据<应该知道的Linux技巧>coolshell上的一篇文章提到的Linux技巧,结合自己掌握的情况进行扩展和总结得来.主要包含下面内容: 一.日常操作 二.数据处理 ...
- android--手机桌面添加网址链接图标(解决方式)
这样的做法最普遍最简单: 1.新建一个android空项目: 2.在drawable文件夹下加入图标文件,如icon.png:在values文件夹下的strings.xml文件里添加名称.如websi ...
- C#语言实现ArcGIS数据源重置之Set Data Source功能
1.须要:依据选择的Mxd路径和目标数据源路径进行重置数据源.此处以(.Mdb为例): 主要利用到的接口: (1)IMapDocument (2)IMapControl2 (3)IWor ...
- Android getTopActivity的方法
使用例如以下方法能够获得top activity 的name public String getTopActivityPackageName(Context context) { String top ...