设为首页 加入收藏

TOP

poj 1416 Shredding Company dfs(一)
2015-07-20 17:43:52 来源: 作者: 【 】 浏览:6
Tags:poj 1416 Shredding Company dfs

Description

You have just been put in charge of developing a new shredder for the Shredding Company Although a "normal" shredder would just shred sheets of paper into little pieces so that the contents would become unreadable, this new shredder needs to have the following unusual basic characteristics.

1.The shredder takes as input a target number and a sheet of paper with a number written on it.

2.It shreds (or cuts) the sheet into pieces each of which has one or more digits on it.

3.The sum of the numbers written on each piece is the closest possible number to the target number, without going over it.

For example, suppose that the target number is 50, and the sheet of paper has the number 12346. The shredder would cut the sheet into four pieces, where one piece has 1, another has 2, the third has 34, and the fourth has 6. This is because their sum 43 (= 1 + 2 + 34 + 6) is closest to the target number 50 of all possible combinations without going over 50. For example, a combination where the pieces are 1, 23, 4, and 6 is not valid, because the sum of this combination 34 (= 1 + 23 + 4 + 6) is less than the above combination's 43. The combination of 12, 34, and 6 is not valid either, because the sum 52 (= 12 + 34 + 6) is greater than the target number of 50.
\
Figure 1. Shredding a sheet of paper having the number 12346 when the target number is 50


There are also three special rules :

1.If the target number is the same as the number on the sheet of paper, then the paper is not cut.

For example, if the target number is 100 and the number on the sheet of paper is also 100, then

the paper is not cut.

2.If it is not possible to make any combination whZ??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vc2Ugc3VtIGlzIGxlc3MgdGhhbiBvciBlcXVhbCB0byB0aGUgdGFyZ2V0IG51bWJlciwgdGhlbiBlcnJvciBpcyBwcmludGVkIG9uIGEgZGlzcGxheS4gRm9yIGV4YW1wbGUsIGlmIHRoZSB0YXJnZXQgbnVtYmVyIGlzIDEgYW5kIHRoZSBudW1iZXIgb24gdGhlIHNoZWV0IG9mIHBhcGVyIGlzIDEyMywgaXQgaXMgbm90IHBvc3NpYmxlIHRvIG1ha2UgYW55IHZhbGlkCiBjb21iaW5hdGlvbiwgYXMgdGhlIGNvbWJpbmF0aW9uIHdpdGggdGhlIHNtYWxsZXN0IHBvc3NpYmxlIHN1bSBpc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oZSBzaHJlZGRlciBzaG91bGQg"cut up" the second number.

Input

The input consists of several test cases, each on one line, as follows :

tl num1
t2 num2
...
t
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Leetcode dfs Path SumII 下一篇Leetcode dp Word Break

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·常用meta整理 | 菜鸟 (2025-12-25 01:21:52)
·SQL HAVING 子句:深 (2025-12-25 01:21:47)
·SQL CREATE INDEX 语 (2025-12-25 01:21:45)
·Shell 传递参数 (2025-12-25 00:50:45)
·Linux echo 命令 - (2025-12-25 00:50:43)