中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-11-10 22:16
47,815 topics / 349,930 posts / today 0 new / 48,291 members
DOS批处理 & 脚本技术(批处理室) » [Help] How to find out which numbers in the text add up to a specified value
Printable Version  4,940 / 48
Floor31 slore Posted 2007-03-03 22:05
铂金会员 Posts 2,478 Credits 5,212
Just give one randomly? Then it can only be that replacing the 39th one with 4764... Then there is a unique solution...

This depends on the situation. Otherwise, the amount of calculation is too large. You see the number of accumulation times I mentioned! Tens of powers of 2...

The method I think is the most economical is:
1. Sorting
2. Judging the number of numbers at least and at most.
3. Enumerating the numbers in these 2...
( I'll find this enumeration process later, too lazy to think again, but the more numbers, the more the operation...)
Floor32 qjbm Posted 2007-03-04 00:21
初级用户 Posts 44 Credits 125
Here comes permutations and combinations again!

There is no simple algorithm.

n = number of numbers in the array
r = from 1 to the sum of numbers in the array
Enumerate in nCr to see if there is a match.....


This kind of program is not suitable to run on a 32-bit system after being written...

--------------------------------------
If only to solve this problem, the recursive code of brother qzwqzw can be slightly modified.
But the calculation speed still depends on luck........

Good luck!
Got the first result when performing the 103rd calculation:


Still that sentence, this problem is not suitable to be solved in a 32-bit system environment.
The following attachment is 321 results obtained after 220,000 calculations!!!!!!

[ Last edited by qjbm on 2007-3-3 at 02:29 PM ]

Attachments
结果.txt (60.98 KiB)
Floor33 youxi01 Posted 2007-03-04 01:21
高级用户 Posts 247 Credits 846 From 湖南==》广东
TO 26F:
If considering repeated numbers,
The largest number combination is only 35, not 38!
The smallest number combination requires 38.
So, the actual number of digits can be 35, 36, 37, 38, etc.
If following the conventional method, according to the permutation and combination rules, the number will be extremely large! I have announced my withdrawal and look forward to experts.
Floor34 slore Posted 2007-03-04 01:31
铂金会员 Posts 2,478 Credits 5,212
Originally posted by youxi01 at 2007-3-3 12:21:
TO 26F:
If considering repeated numbers,
The largest number combination only has 35, not 38!
The smallest number combination needs 38
So, the real number of digits has cases such as 35, 36, 37, 38, etc.
Such as...



Oh, got the meaning......

[ Last edited by slore on 2007-3-3 at 12:47 PM ]
Floor35 youxi01 Posted 2007-03-04 03:12
高级用户 Posts 247 Credits 846 From 湖南==》广东
No way, the efficiency is so low. Then when I get old, it might not be fully calculated yet
Floor36 20080610 Posted 2007-03-04 03:41
初级用户 Posts 34 Credits 83
Under ideal conditions, filter from these results.
72!/(35!(72-35)!) + 72!/(36!(72-36)!) + 72!/(37!(72-37)!) + 72!/(38!(72-38)!)
Floor37 qjbm Posted 2007-03-04 03:48
初级用户 Posts 44 Credits 125
72!/35!(72-35)! + 72!/36!(72-36)! + 72!/37!(72-37)! + 72!/38!(72-38)!

n = number of elements in the array
r = from 35 to 38
Enumerate in nCr to see if there are eligible ones.....

The same. Massive calculation mode!!
Floor38 20080610 Posted 2007-03-04 03:50
初级用户 Posts 34 Credits 83
Batch processing should be something that can't be completed...
Floor39 slore Posted 2007-03-04 05:26
铂金会员 Posts 2,478 Credits 5,212
Gave up...
The enumeration code has been written... It's too slow for the operation.
No response... Closed. Too many numbers..
Floor40 Primalchaos Posted 2007-03-04 05:28
初级用户 Posts 19 Credits 41
Why doesn't the person upstairs publish the code so that we can learn from it?
Floor41 slore Posted 2007-03-04 05:41
铂金会员 Posts 2,478 Credits 5,212
Not written with p...
The P operation is even slower...

It's recursion and so on... Search online for combination recursion. There are many algorithms, for Delphi, C, VB...
Floor42 Primalchaos Posted 2007-03-04 06:19
初级用户 Posts 19 Credits 41
Then can the brother provide the C language code?
Floor43 slore Posted 2007-03-04 06:35
铂金会员 Posts 2,478 Credits 5,212
Floor44 youxi01 Posted 2007-03-04 07:34
高级用户 Posts 247 Credits 846 From 湖南==》广东
I don't know why, the 36-digit combinations I wrote out are much more numerous than the groups of 32F?! The code is more efficient than 32F, but it's still not enough. I'm testing it and will post it later.
Floor45 youxi01 Posted 2007-03-04 07:48
高级用户 Posts 247 Credits 846 From 湖南==》广东
The code is as follows, welcome to test and give corrections.

Description: This section of code is for the situation when there are 36 number combinations. Other situations are not considered. Please change it yourself if needed.

[ Last edited by youxi01 on 2007-3-4 at 07:50 AM ]
Prev  1 2 3 4  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023