如何評價《職人介紹所》第 21 期節目,以及嘉賓 趙劼 和 winter 的表現?

時間 2021-05-11 23:21:13

1樓:范德成

為了理解winter原先的演算法,寫了乙個帶UT的python版本。原帖中winter和老趙的時間複雜度分析很值得細細品味。import sys

import traceback

def main():

run_tests()

indexed_arr = generate_array()

print("Official result: ".format(k_sum(indexed_arr, 3, len(indexed_arr), 0, create_cachereturn 0

def run_tests():

test_one_sum()

test_find_k_sum_all_results()

test_k_sum()

print("")

def test_one_sum():

try4

arr = [1, 2, 3, 4, 5cache = create_cacheresult = one_sum(conv_to_indexed_array(arr), len(arr), 4, cacheif result != [(4, 3raise ValueError("result not expected: ".

format(result1

arr = [1, 2, 3, 4, 5cache = create_cacheresult = one_sum(conv_to_indexed_array(arr), len(arr), 1, cacheif result != [(1, 0raise ValueError("result not expected: ".

format(result5

arr = [1, 2, 3, 4, 5cache = create_cacheresult = one_sum(conv_to_indexed_array(arr), len(arr), 5, cacheif result != [(5, 4raise ValueError("result not expected: ".

format(resultNon-existent

arr = [1, 2, 3, 4, 5cache = create_cacheresult = one_sum(conv_to_indexed_array(arr), len(arr), 0, cacheif result != Noneraise ValueError("result not expected: ".

format(resultsys.stdout.write(".

"sys.stdout.flush()

except ValueError as extraceback.print_exc()

def test_find_k_sum_all_results():

try9 = 1 + 3 + 5 = 2 + 3 + 4

arr = [1, 2, 3, 4, 5result = find_k_sum_all_results(conv_to_indexed_array(arr), 3, 9Sort by the number

result.sortif result != [[(1, 0), (3, 2), (5, 4)], [(2, 1), (3, 2), (4, 3raise ValueError("result not expected:

".format(result21 = 3 + 8 + 10 = 3 + 9 + 9arr = [9, 8, 4, 9, 5, 5, 10, 1, 3, 7result = find_k_sum_all_results(conv_to_indexed_array(arr), 3, 21Sort by the number

result.sortif [(3, 8), (8, 1), (10, 6)] not in resultraise ValueError("result not expected: ".

format(resultif [(3, 8), (9, 0), (9, 3)] not in resultraise ValueError("result not expected: ".format(result100 is not achieveable by the array elements

arr = [9, 8, 4, 9, 5, 5, 10, 1, 3, 7result = find_k_sum_all_results(conv_to_indexed_array(arr), 3, 100if len(result) != 0raise ValueError("result is not an empty array--".format(resultsys.

stdout.write("."sys.

stdout.flush()

except ValueError as extraceback.print_exc()

def test_k_sum():

try9 = 1 + 3 + 5 = 2 + 3 + 4

arr = [1, 2, 3, 4, 5k = 3

n = 9

cache = create_cacheresult = k_sum(conv_to_indexed_array(arr), k, len(arr), n, cacheSort by the number

result.sortif result not in find_k_sum_all_results(conv_to_indexed_array(arr), k, nraise ValueError("result not expected: ".

format(resultcount: 27print("Count is ".format(cache["count൜ = 3 + 8 + 9arr = [9, 8, 4, 9, 5, 5, 10, 1, 3, 7k = 3

n = 20

cache = create_cacheresult = k_sum(conv_to_indexed_array(arr), k, len(arr), n, cacheSort by the number

result.sortif result not in find_k_sum_all_results(conv_to_indexed_array(arr), k, nraise ValueError("result not expected: ".

format(resultcount: 33print("Count is ".format(cache["count蔴 is not achieveable by the array elements

arr = [9, 8, 4, 9, 5, 5, 10, 1, 3, 7k = 3

n = 100

cache = create_cacheresult = k_sum(conv_to_indexed_array(arr), k, len(arr), n, cacheif result != Noneraise ValueError("result is not None--".format(result100 array 1, rand 0

arr = get_100_array_1k = 3

n = get_100_3_sum_rnd(0cache = create_cacheresult = k_sum(conv_to_indexed_array(arr), k, len(arr), n, cacheSort by the number

result.sortif result not in find_k_sum_all_results(conv_to_indexed_array(arr), k, nraise ValueError("result not expected: ".

format(resultcount: 240625print("Count is ".format(cache["count蔴 array 1, rand 1

arr = get_100_array_1k = 3

n = get_100_3_sum_rnd(1cache = create_cacheresult = k_sum(conv_to_indexed_array(arr), k, len(arr), n, cacheSort by the number

result.sortif result not in find_k_sum_all_results(conv_to_indexed_array(arr), k, nraise ValueError("result not expected: ".

format(resultcount: 419527print("Count is ".format(cache["count蔴 array 1, rand 2

arr = get_100_array_1k = 3

n = get_100_3_sum_rnd(2cache = create_cacheresult = k_sum(conv_to_indexed_array(arr), k, len(arr), n, cacheSort by the number

result.sortif result not in find_k_sum_all_results(conv_to_indexed_array(arr), k, nraise ValueError("result not expected: ".

format(resultcount: 255print("Count is ".format(cache["count蔴 array 1, rand 3

arr = get_100_array_1k = 3

n = get_100_3_sum_rnd(3cache = create_cacheresult = k_sum(conv_to_indexed_array(arr), k, len(arr), n, cacheSort by the number

result.sortif result not in find_k_sum_all_results(conv_to_indexed_array(arr), k, nraise ValueError("result not expected: ".

format(resultcount: 8595print("Count is ".format(cache["count蔴 array 2, rand 0

arr = get_100_array_2k = 3

n = get_100_3_sum_rnd(0cache = create_cacheresult = k_sum(conv_to_indexed_array(arr), k, len(arr), n, cacheSort by the number

result.sortif result not in find_k_sum_all_results(conv_to_indexed_array(arr), k, nraise ValueError("result not expected: ".

format(resultcount: 103928print("Count is ".format(cache["count蔴 array 2, rand 1

arr = get_100_array_2k = 3

n = get_100_3_sum_rnd(1cache = create_cacheresult = k_sum(conv_to_indexed_array(arr), k, len(arr), n, cacheSort by the number

result.sortif result not in find_k_sum_all_results(conv_to_indexed_array(arr), k, nraise ValueError("result not expected: ".

format(resultcount: 103917print("Count is ".format(cache["count蔴 array 2, rand 2

arr = get_100_array_2k = 3

n = get_100_3_sum_rnd(2cache = create_cacheresult = k_sum(conv_to_indexed_array(arr), k, len(arr), n, cacheSort by the number

result.sortif result not in find_k_sum_all_results(conv_to_indexed_array(arr), k, nraise ValueError("result not expected: ".

format(resultcount: 678print("Count is ".format(cache["count蔴 array 2, rand 3

arr = get_100_array_2k = 3

n = get_100_3_sum_rnd(3cache = create_cacheresult = k_sum(conv_to_indexed_array(arr), k, len(arr), n, cacheSort by the number

result.sortif result not in find_k_sum_all_results(conv_to_indexed_array(arr), k, nraise ValueError("result not expected: ".

format(resultcount: 598680print("Count is ".format(cache["count? array 1, rand 0

arr = get_1000_array_1k = 3

n = get_1000_3_sum_rnd(0cache = create_cacheresult = k_sum(conv_to_indexed_array(arr), k, len(arr), n, cacheSort by the number

result.sortif result not in find_k_sum_all_results(conv_to_indexed_array(arr), k, nraise ValueError("result not expected: ".

format(resultcount: 8688print("Count is ".format(cache["count? array 1, rand 1

arr = get_1000_array_1k = 3

n = get_1000_3_sum_rnd(1cache = create_cacheresult = k_sum(conv_to_indexed_array(arr), k, len(arr), n, cacheSort by the number

result.sortif result not in find_k_sum_all_results(conv_to_indexed_array(arr), k, nraise ValueError("result not expected: ".

format(resultcount: 46150print("Count is ".format(cache["count? array 2, rand 2

arr = get_1000_array_2k = 3

n = get_1000_3_sum_rnd(2cache = create_cacheresult = k_sum(conv_to_indexed_array(arr), k, len(arr), n, cacheSort by the number

result.sortif result not in find_k_sum_all_results(conv_to_indexed_array(arr), k, nraise ValueError("result not expected: ".

format(resultcount: 6212print("Count is ".format(cache["count? array 2, rand 3

arr = get_1000_array_2k = 3

n = get_1000_3_sum_rnd(3cache = create_cacheresult = k_sum(conv_to_indexed_array(arr), k, len(arr), n, cacheSort by the number

result.sortif result not in find_k_sum_all_results(conv_to_indexed_array(arr), k, nraise ValueError("result not expected: ".

format(resultcount: 6290print("Count is ".format(cache["count"sys.

stdout.write("."sys.

stdout.flush()

except ValueError as extraceback.print_exc()

def k_sum(indexed_arr, k, i, n, cache):

cache["count"] += 1

if (k, i, n) in cachereturn cache[(k, i, n)]

if k == 1return one_sum(indexed_arr, i, n, cache)

result = None

for (curr_idx, (num, index)) in enumerate(indexed_arrcache["count"] += i - 1 # For slicing the array

ret = k_sum(indexed_arr[:curr_idx] + indexed_arr[curr_idx + 1:], k - 1i - 1, n - num, cacheif ret !

= Nonecache["count"] += k # For building the arrayresult = ret + [(num, indexcache[(k, i, n)] = resultreturn result

return result

def one_sum(indexed_arr, i, n, cache):

cache["count"] += 1

if (1, i, n) in cachereturn cache[(1, i, n)]

result = None

for (num, index) in indexed_arrcache["count"] += 1

if num == nresult = [(num, indexcache[(1, i, n)] = resultreturn result

return result

def conv_to_indexed_array(arr):

return result

def generate_array():

result = [2, 5, 1, -6, 5, 8, 3, 9, 0, 8]

return conv_to_indexed_array(result)

def get_100_array_1():

return [ 8, 52, 55, 74, 15, 33, 68, 35, 24, 65, 44, 50, 89, 44, 36, 63, 8140, 55, 58, 77, 100, 59, 53, 55, 68, 35, 36, 85, 90, 60, 75, 5591, 7, 88, 99, 39, 54, 74, 58, 82, 50, 3, 90, 36, 88, 5, 93, 2197, 67, 81, 17, 44, 17, 36, 44, 30, 37, 40, 47, 61, 21, 55, 22, 9932, 32, 54, 84, 36, 77, 88, 6, 71, 18, 65, 18, 9, 14, 1, 22, 5856, 20, 57, 13, 75, 98, 34, 25, 85, 53, 86, 66, 99, 17, 32, 45, ]

def get_100_array_2():

return [ 88, 24, 65, 20, 59, 96, 78, 48, 71, 52, 16, 44, 59, 36, 47, 7085, 64, 30, 93, 87, 60, 46, 61, 83, 69, 36, 97, 19, 15, 2, 59, 5098, 61, 71, 15, 47, 2, 84, 22, 71, 84, 65, 40, 64, 79, 38, 12, 7335, 8, 60, 21, 96, 98, 66, 65, 34, 76, 66, 16, 51, 62, 80, 95, 4121, 93, 89, 80, 92, 46, 78, 64, 36, 83, 49, 83, 66, 47, 90, 74, 8221, 1, 25, 32, 44, 13, 63, 82, 57, 50, 3, 89, 44, 43, 19, 87, ]

def get_100_3_sum_rnd(index):

if index == 0return 288

elif index == 1return 289

elif index == 2return 157

elif index == 3return 17

elseraise ValueError("Invalid index--".format(index))

def get_1000_array_1():

return [ 404, 118, 227, 795, 986, 803, 602, 920, 839, 731, 648, 474, 636954, 995, 740, 510, 339, 522, 971, 576, 978, 380, 95, 650, 588632, 441, 989, 820, 525, 753, 789, 865, 180, 410, 738, 660, 102669, 716, 159, 745, 260, 539, 594, 241, 761, 368, 35, 129, 380754, 720, 885, 130, 892, 693, 386, 840, 131, 863, 725, 580, 510123, 109, 117, 259, 683, 257, 716, 539, 658, 532, 691, 68, 300356, 985, 365, 640, 815, 322, 481, 259, 214, 805, 393, 172, 94120, 451, 357, 582, 669, 292, 253, 717, 202, 298, 477, 20, 238548, 337, 561, 474, 271, 648, 862, 974, 773, 69, 432, 961, 976435, 928, 273, 950, 652, 772, 435, 727, 388, 523, 22, 249, 7, 729766, 306, 888, 848, 828, 226, 267, 308, 176, 925, 341, 2, 892, 269610, 202, 8, 246, 98, 36, 381, 620, 927, 970, 916, 322, 429, 241237, 180, 979, 139, 322, 777, 851, 319, 770, 140, 853, 332, 937826, 158, 89, 645, 781, 976, 896, 808, 778, 561, 702, 534, 62, 331244, 977, 620, 324, 776, 33, 486, 488, 477, 837, 363, 782, 607768, 416, 581, 483, 46, 363, 168, 728, 445, 283, 368, 552, 604818, 584, 208, 553, 307, 560, 115, 605, 57, 953, 623, 935, 97, 313555, 160, 54, 616, 560, 257, 242, 794, 432, 170, 266, 44, 467, 213753, 62, 33, 139, 789, 695, 759, 424, 635, 217, 208, 295, 449, 331205, 399, 720, 440, 145, 378, 922, 278, 327, 595, 580, 65, 271754, 87, 392, 851, 123, 115, 70, 544, 535, 202, 848, 815, 743, 974271, 796, 653, 926, 796, 173, 956, 404, 359, 712, 988, 799, 148, 1800, 75, 947, 723, 727, 964, 468, 168, 202, 514, 86, 243, 48, 64669, 48, 824, 702, 799, 534, 325, 388, 696, 243, 347, 159, 729, 955, 274, 597, 651, 275, 352, 249, 865, 887, 967, 899, 266, 320, 327931, 141, 947, 965, 654, 4, 932, 409, 834, 672, 998, 63, 468, 732582, 91, 828, 946, 436, 753, 821, 61, 580, 20, 626, 257, 251, 347165, 842, 390, 634, 686, 9, 235, 939, 569, 250, 957, 637, 580, 719355, 675, 465, 63, 641, 692, 291, 704, 620, 92, 168, 854, 864, 628568, 108, 302, 368, 688, 592, 770, 503, 798, 841, 828, 760, 84596, 926, 109, 812, 231, 259, 317, 178, 168, 831, 12, 457, 280, 606582, 382, 587, 732, 164, 884, 796, 735, 377, 517, 988, 990, 82722, 447, 325, 142, 432, 225, 572, 503, 401, 790, 985, 258, 107850, 1000, 539, 971, 309, 917, 50, 860, 543, 452, 753, 885, 37805, 619, 381, 459, 373, 652, 357, 706, 513, 748, 26, 655, 563938, 199, 448, 578, 398, 97, 131, 805, 213, 390, 947, 485, 358837, 26, 354, 963, 915, 483, 695, 227, 169, 185, 597, 908, 590904, 314, 323, 355, 452, 799, 768, 252, 508, 407, 586, 499, 162618, 838, 916, 792, 817, 524, 37, 175, 280, 603, 199, 736, 378, 28108, 347, 24, 119, 106, 10, 976, 754, 970, 166, 785, 401, 818, 114940, 697, 540, 667, 490, 749, 686, 631, 363, 719, 205, 302, 76392, 697, 181, 452, 787, 229, 968, 827, 131, 256, 885, 750, 855661, 72, 595, 422, 33, 242, 835, 56, 339, 879, 241, 439, 246, 20722, 27, 179, 947, 881, 462, 930, 72, 923, 330, 940, 338, 526, 498642, 350, 96, 169, 183, 147, 36, 604, 507, 521, 722, 267, 706, 482292, 739, 760, 478, 523, 619, 728, 295, 869, 759, 570, 732, 562528, 670, 449, 123, 52, 425, 814, 598, 257, 584, 195, 285, 373229, 954, 17, 371, 140, 237, 28, 596, 370, 892, 934, 476, 786, 46291, 366, 991, 725, 101, 881, 998, 529, 856, 957, 613, 657, 573951, 516, 775, 785, 972, 687, 222, 461, 171, 488, 52, 421, 76, 83496, 862, 454, 184, 623, 399, 898, 164, 598, 593, 326, 101, 652, 860, 901, 338, 23, 921, 864, 376, 189, 699, 503, 789, 694, 315, 593969, 23, 1000, 186, 180, 156, 615, 511, 334, 803, 685, 818, 641697, 542, 351, 296, 157, 163, 2, 857, 379, 576, 255, 509, 603, 513683, 760, 37, 549, 601, 423, 200, 133, 577, 223, 184, 104, 259508, 924, 998, 950, 88, 520, 176, 8, 476, 217, 160, 299, 947, 999324, 452, 647, 865, 689, 463, 767, 481, 184, 173, 715, 686, 767664, 739, 16, 267, 99, 483, 848, 311, 639, 508, 209, 576, 500, 894875, 391, 197, 583, 539, 571, 561, 479, 153, 125, 389, 481, 613455, 731, 547, 808, 633, 952, 518, 943, 112, 742, 535, 662, 143345, 158, 606, 138, 369, 607, 531, 325, 819, 497, 563, 794, 841355, 967, 688, 162, 398, 575, 185, 224, 620, 936, 857, 815, 793371, 159, 51, 876, 614, 965, 623, 507, 493, 23, 412, 13, 513, 304456, 842, 243, 734, 622, 663, 850, 353, 856, 771, 786, 243, 273714, 630, 297, 157, 981, 330, 718, 540, 413, 845, 802, 976, 651237, 164, 760, 571, 536, 191, 541, 787, 634, 459, 166, 242, 347812, 155, 769, 247, 112, 55, 202, 403, 101, 842, 498, 855, 250696, 751, 964, 899, 789, 318, 453, 570, 470, 158, 104, 169, 281318, 407, 564, 989, 784, 840, 404, 909, 465, 113, 642, 667, 994280, 489, 664, 666, 985, 972, 82, 490, 669, 433, 93, 875, 439, 477538, 415, 796, 482, 548, 596, 899, 762, 540, 12, 195, 234, 697771, 669, 18, 416, 387, 713, 522, 713, 93, 630, 43, 736, 237, 165769, 187, 577, 690, 707, 54, 769, 735, 823, 640, 426, 918, 695, 76100, 105, 403, 623, 976, 320, 600, 857, 176, 300, 660, 911, 604742, 179, 142, 445, 637, ]

def get_1000_array_2():

return [ 289, 552, 459, 938, 42, 986, 108, 746, 199, 716, 196, 834, 518677, 133, 251, 534, 149, 317, 482, 855, 402, 825, 87, 817, 370687, 448, 886, 630, 461, 921, 589, 765, 312, 160, 572, 854, 682481, 741, 529, 591, 344, 174, 699, 281, 11, 686, 893, 13, 89, 769556, 219, 21, 444, 440, 195, 650, 921, 554, 435, 547, 366, 184502, 969, 588, 231, 201, 498, 401, 168, 197, 696, 797, 259, 668836, 992, 360, 189, 171, 112, 215, 840, 625, 619, 980, 395, 908183, 424, 416, 249, 570, 556, 851, 706, 356, 5, 899, 137, 905, 393743, 128, 597, 878, 47, 913, 716, 307, 984, 364, 802, 242, 882790, 156, 659, 599, 317, 453, 714, 736, 999, 236, 434, 144, 110644, 829, 496, 376, 463, 75, 367, 743, 114, 33, 63, 996, 956, 270753, 930, 785, 587, 211, 331, 219, 806, 312, 288, 184, 425, 747665, 342, 374, 441, 863, 519, 309, 493, 867, 272, 659, 985, 709550, 971, 263, 100, 767, 765, 618, 811, 902, 212, 493, 387, 616141, 461, 607, 269, 426, 417, 284, 669, 766, 764, 377, 71, 386100, 506, 21, 843, 829, 589, 466, 556, 767, 761, 590, 282, 849982, 89, 616, 171, 562, 889, 389, 437, 875, 314, 68, 845, 16, 259258, 35, 725, 636, 772, 433, 30, 923, 715, 995, 83, 242, 745, 8271000, 652, 851, 482, 825, 123, 23, 142, 187, 396, 337, 430, 156783, 173, 693, 952, 949, 429, 19, 186, 680, 499, 856, 90, 149, 604161, 348, 876, 222, 968, 884, 855, 255, 115, 418, 524, 699, 874699, 759, 959, 863, 126, 979, 240, 885, 179, 721, 990, 823, 903583, 87, 6, 506, 341, 461, 61, 462, 786, 139, 763, 381, 226, 61132, 237, 477, 516, 848, 483, 89, 786, 815, 277, 622, 610, 487, 807108, 694, 859, 77, 585, 1000, 292, 693, 460, 725, 389, 508, 65268, 35, 125, 946, 821, 184, 536, 641, 704, 169, 43, 122, 839, 28382, 399, 337, 937, 439, 684, 66, 630, 463, 540, 471, 351, 691, 382736, 530, 47, 81, 653, 928, 783, 163, 105, 34, 163, 671, 217, 269921, 341, 224, 173, 754, 897, 334, 815, 837, 671, 643, 131, 42038, 205, 258, 468, 374, 184, 998, 763, 26, 877, 782, 752, 58, 9123, 475, 683, 601, 249, 840, 486, 158, 540, 660, 172, 377, 738351, 286, 800, 739, 155, 484, 494, 277, 438, 370, 352, 106, 467612, 424, 810, 523, 528, 306, 434, 415, 933, 54, 857, 473, 165677, 119, 820, 687, 126, 641, 918, 382, 628, 640, 939, 136, 888802, 390, 727, 537, 390, 806, 92, 206, 128, 664, 313, 773, 924853, 439, 899, 996, 533, 21, 737, 468, 556, 372, 870, 145, 434683, 824, 657, 64, 262, 511, 318, 579, 172, 104, 600, 155, 127, 67733, 864, 647, 526, 733, 605, 973, 374, 461, 374, 788, 28, 315251, 860, 605, 473, 302, 845, 117, 645, 557, 622, 396, 615, 396180, 205, 956, 531, 688, 288, 660, 317, 173, 675, 423, 714, 878651, 286, 193, 661, 955, 892, 101, 604, 358, 315, 117, 850, 113564, 204, 426, 487, 805, 936, 842, 664, 366, 974, 917, 32, 498, 15573, 22, 432, 398, 701, 705, 998, 294, 646, 252, 629, 605, 386375, 92, 73, 840, 389, 767, 590, 562, 329, 132, 547, 643, 932, 631731, 776, 471, 337, 246, 3, 674, 606, 512, 20, 134, 640, 388, 438750, 927, 286, 510, 371, 157, 417, 146, 966, 483, 422, 474, 765393, 259, 473, 129, 306, 826, 276, 263, 654, 854, 550, 433, 81968, 271, 286, 917, 470, 537, 851, 459, 253, 760, 596, 383, 27856, 577, 993, 485, 470, 578, 575, 749, 862, 147, 987, 243, 849134, 91, 223, 271, 811, 975, 292, 441, 681, 837, 881, 649, 906746, 389, 278, 808, 892, 599, 482, 319, 404, 91, 687, 481, 62, 970571, 683, 6, 824, 353, 617, 796, 637, 645, 423, 223, 556, 861, 409162, 183, 274, 957, 211, 141, 108, 50, 312, 238, 829, 243, 814629, 915, 102, 839, 599, 719, 997, 862, 330, 644, 805, 761, 296205, 350, 112, 492, 856, 359, 907, 774, 170, 65, 420, 295, 383, 68814, 958, 201, 519, 961, 871, 566, 523, 706, 64, 911, 279, 190727, 912, 36, 281, 350, 239, 940, 416, 836, 631, 307, 26, 933, 714112, 471, 976, 60, 146, 850, 366, 358, 788, 48, 37, 368, 1, 915616, 5, 357, 21, 733, 606, 558, 469, 218, 917, 241, 1000, 493, 5669, 155, 499, 40, 480, 891, 530, 82, 957, 533, 923, 837, 280, 37314, 835, 189, 492, 283, 683, 393, 101, 601, 194, 220, 413, 654510, 906, 675, 420, 375, 235, 922, 899, 100, 767, 206, 621, 662780, 650, 924, 573, 946, 752, 66, 366, 703, 198, 603, 684, 613, 38528, 122, 379, 506, 894, 420, 706, 904, 783, 736, 414, 602, 958849, 820, 617, 701, 317, 188, 837, 711, 979, 477, 98, 739, 849, 6722, 533, 54, 561, 513, 583, 655, 774, 87, 313, 194, 235, 525, 31344, 529, 871, 252, 495, 417, 812, 143, 684, 708, 370, 239, 580641, 829, 147, 236, 18, 363, 977, 891, 894, 667, 848, 54, 153, 733687, 434, 501, 897, 245, 321, 569, 892, 274, 127, 810, 306, 495742, 947, 82, 912, 554, 107, 32, 506, 805, 563, 504, 618, 834, 51428, 210, 581, 960, 98, 48, 913, 307, 433, 105, 726, 876, 526, 940786, 517, 287, 616, 29, 151, 638, 935, 930, 95, 479, 808, 869, 150416, 1000, 43, 595, 329, 350, 602, 451, 149, 273, 404, 133, 463607, 39, 407, 788, 608, 953, 879, 137, 320, 11, 240, 744, 826, 944899, 282, 777, 170, 143, 666, 840, ]

def get_1000_3_sum_rnd(index):

if index == 0return 2291

elif index == 1return 823

elif index == 2return 2209

elif index == 3return 2217

elseraise ValueError("Invalid index--".format(index))

def find_k_sum_all_results(indexed_arr, k, n):

indexed_set = set(indexed_arr)

result = find_k_sum_all_results_rec(indexed_set, k, n)

result = [list(x) for x in result]

return result

def find_k_sum_all_results_rec(indexed_set, k, n):

if k == 1return find_one_sum_all_results(indexed_set, n)

result = set()

for (num, index) in indexed_setindexed_set.remove((num, index)) # Take the number before recursion

ret = find_k_sum_all_results_rec(indexed_set, k - 1, n - numWe sort the result, so that duplicate ones can automatically beeliminatedA set needs to use tuples rather than lists as members

result.update([tuple(sort_indexed_iterable(list(x) + [(num, indexfor x in retindexed_set.add((num, index)) # Put the number back

return result

def sort_indexed_iterable(indexed_iterable):

sorted_list = list(indexed_iterable)

sorted_list.sort()

return sorted_list

def find_one_sum_all_results(indexed_set, n):

result = set()

for (num, index) in indexed_setif num == nresult.add(((num, index),))

return result

def create_cache():

return

sys.exit(main())

如何評價《職人介紹所》第 6 期節目,以及嘉賓梁邊妖和 yolfilm 的表現?

雨鶴千波 主要是節目組的問題。當然,同時這也告訴我們,好好利用大學每乙個做presentation的機會鍛鍊自己,老師指出自己不足時好好聽著,我們老師會提出各種不足,比如你和別人說話時表情,態度,開頭說什麼比較禮貌,講話過程中肢體語言,等等。老師常說的一句話,工作中要有讀過書的人的素質,不然別人會懷...

如何評價火影忍者博人傳第21集?

楊永明 沒有博人的博人傳還是挺好看的。都說鳴佐被削弱,我到不這麼認為。遇見乙個新對手,先來試探一下看看你什麼水平,想辦法活捉你。所以打的才比較慢。加上鳴人不想殺人,但是始終自認在掌控局面。 剛看了第23集,打鬥不錯,終於正經了一回,宇智波趙信也沒有大家說的那麼水,挺厲害的,也是屬於拆遷辦的那種,絕對...

如何評價網劇《穿越火線》第21集?

MengM 還是一樣,有涉及到遊戲戰術的我就來答一下 首先1coin這集在手感不佳的時候選擇了很明智的做法,開局架槍防前壓,壓縮時間,抓住保衛者一整局高壓的心態來打一波 fps遊戲越壓縮時間,防守方壓力越大,因為真的不知道什麼時候自己防守的區域就會突然下雨然後一窩蜂衝進來一群人,自己一但最不到1換n...