PAT-1076. Forwards on Weibo (30)

消失了好久。。我又回来了...

继续PAT,今天终于做了道30分的题目。。发现c++还是比java好写啊,而且提交的时候终于不用担心超时了


为了突出重点,把题目放到最后把。今天主要是一道DFS的题。

思路如下:

1,邻接表存储图;

2,应用深度优先搜索,但是有深度的限定。

要注意:

①题目所给的形式不能直接建表,要反过来建;

②计数的时候除了设定visited[]数组标记是否访问,还要设定bAdded[]数组标记是否计算过。


题目:

Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a user makes a post on Weibo, all his/her followers can view and forward his/her post, which can then be forwarded again by their followers. Now given a social network, you are supposed to calculate the maximum potential amount of forwards for any specific user, assuming that only L levels of indirect followers

你可能感兴趣的:(PAT)