SPOJ GREED - Greedy island(费用流)

本文介绍了SPOJ中的GREED问题,即在贪婪岛上通过最小成本交换卡片来构建1到N的序列。利用最大流和最小费用流的方法,帮助Gon以最低代价获得离开游戏所需的卡片。文章提供了输入输出格式和样例,并描述了通过建立图来解决问题的策略。
摘要由CSDN通过智能技术生成

GREED - Greedy island

#max-flow #minimum-cost-flow

 

Gon is on Greedy island. He wants to go home. But to get the ticket to leave the game, he has to get N cards labeled in a sequence from 1 to N (the order of the cards in his hand is irrelevant). He already has N cards, but not forming a sequence from 1 to N. So he wants you to help him. For some cards, he can change one card for another for one piece of gold. Help him to get the ticket at the minimum cost (using the minimum number of exchanges).

Input

The first line contains t, the number of tests (1<=t<=10). For each test case:

  • the number of cards N is given is given in the first line (2<=N<=500).
  • the next N lines contain the N cards owned by Gon.
  • the following l
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值