日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UVa 988 - Many Paths, One Destination

發布時間:2025/3/8 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。