UFO

2020年1月17日 948点热度 0人点赞 0条评论

UFO

时间: 2ms        内存:64M

描述:

UFO likes traveling by bike very much. He intends to travel this summer. Due to lack of money, he must bring things and exchange them with others. When he arrives in a city, he sells everything he has and buys new things. Then he travels to another city, sells his items and buys new ones. In this problem you will have to find the total amount of money UFO will gain on the optimal tour. On a tour he can go to some city more than once, and he must finish his tour in some cities. Also there is a starting city for his tour and the number of inter-city travels he wants to do in his tour.

输入:

The input file contains several test cases. The first line is N: the number of test cases. Then follows N cases. The description of each case is given below: Each case starts with four integers C (2 <= C <= 100), the number of cities, and the cities are numbered from 1 to C, S (1 <= S <= C), the identifier of the starting city, E (1 <= E <= C-1), the number of cities his tour can end at, and T (1 <= T <= 1000), the number of inter-city travels he wants to do. Follow C lines with C non-negative integers which are no more than 1000. The jth integer of the ith line will describe the profit he earns when he goes from city i to city j by selling things. As he does not want to make a trip to a city he is already, the ith integer of the ith line will always be 0. Note that going from city i to city j can have a different profit than going from city j to city i. After there will be a line with E integers, the identifier of the cities he can end his tour.

输出:

For each input case produce one line of output, the total profit he can earn in the corresponding tour.

示例输入:

1
3 1 2 2
0 3 5
5 0 1
9 2 0
2 3

示例输出:

7

提示:

参考答案:

解锁文章

没有看到答案?微信扫描二维码可免费解锁文章

微信扫描二维码解锁

使用微信扫描二维码打开广告页面后可以立即关闭,再刷新此页面即可正常浏览此文章

所跳转广告均由第三方提供,并不代表本站观点!

已经扫描此二维码?点此立即跳转

code

这个人很懒,什么都没留下

文章评论