Beautiful Now (HDU 6351) (dfs + 剪枝,不能用贪心)

Given a positive integer, Anton wants to beautify it with up to k swaps of digits. The problem involves finding the minimum and maximum numbers achievable, avoiding leading zeros and proving that a greedy approach is incorrect. A depth-first search with pruning is suggested as a solution, where the maximum value may require exploring multiple possibilities for the largest trailing digits." 81324423,7828665,layui使用教程:列表数据更新功能实现,"['前端开发', 'JavaScript', 'HTML', 'layui']
摘要由CSDN通过智能技术生成

欢迎访问https://blog.csdn.net/lxt_Lucia~~

宇宙第一小仙女\(^o^)/~萌量爆表求带飞=≡Σ((( つ^o^)つ~ dalao们点个关注呗~

 

--------------------------------我只是一条可爱哒分界线-------------------------------

 

一、问题:

Description

Anton has a positive integer n, however, it quite looks like a mess, so he wants to make it beautiful after k swaps of digits. 
Let the decimal representation of n as  (x1x2⋯xm) satisfying that 1 ≤ x1 ≤ 9, 0 ≤ xi ≤ 9 ( 2 ≤ i ≤ m),which means n = ∑ (i = 1 ~ i = m) xi * 10的 m−i 次方. In each swap, Anton can select two digits xi and xj (1 ≤ i ≤ j ≤ m ) and then swap them if the integer after this swap has no leading zero. 
Could you please tell him the minimum integer and the maximum integer he can obtain after k swaps?

 

Input

The first line contains one integer T, indicating the number of test cases. 
E

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值