ลำดับชุดการเพิ่มที่เพิ่มมากขึ้น


11

พื้นหลัง

ลำดับชุดอดีตที่เพิ่มขึ้นของการสั่งซื้อถูกกำหนดให้เป็นลำดับของชุดจำนวนเต็มซึ่งตอบสนองความต่อไปนี้:S 1 , S 2 , , S nยังไม่มีข้อความS1,S2,,Sn

  • แต่ละเป็นส่วนหนึ่งที่ไม่ว่างเปล่าของ{ 1 , 2 , , N }Sผม{1,2,,ยังไม่มีข้อความ}
  • สำหรับ ,กล่าวคือชุดที่ต่อเนื่องกันสองชุดไม่มีองค์ประกอบที่เหมือนกัน1ผม<nSผมSผม+1=
  • สำหรับค่าเฉลี่ย (ค่าเฉลี่ย) ของเป็นอย่างเคร่งครัดน้อยกว่าที่1}S i S i + 11ผม<nSผมSผม+1

ท้าทาย

ป.ร. ให้ไว้เป็นจำนวนเต็มบวกเอาท์พุทความยาวของอดีตเพิ่มมากขึ้นตามลำดับชุดที่ยาวที่สุดของการสั่งซื้อNN

กรณีทดสอบ

เหล่านี้จะขึ้นอยู่กับผลการค้นหาโดยใช้โครงการออยเลอร์ thundre

1 => 1 // {1}
2 => 2 // {1} {2}
3 => 3 // {1} {2} {3}
4 => 5 // {1} {2} {1,4} {3} {4}
5 => 7 // {1} {2} {1,4} {3} {2,5} {4} {5}
6 => 10 // {1} {2} {1,4} {3} {1,4,5} {2,3,6} {4} {3,6} {5} {6}
7 => 15 // {1} {2} {1,4} {3} {1,2,7} {3,4} {1,2,5,7} {4} {1,3,6,7} {4,5} {1,6,7} {5} {4,7} {6} {7}
8 => 21
9 => 29
10 => 39
11 => 49
12 => 63
13 => 79
14 => 99
15 => 121
16 => 145
17 => 171
18 => 203
19 => 237
20 => 277
21 => 321
22 => 369
23 => 419
24 => 477
25 => 537

กฎระเบียบ

ใช้กฎมาตรฐานของการส่งที่ถูกต้องสั้นที่สุดในหน่วยไบต์ชนะ

เงินรางวัล

ปัญหานี้ได้รับการพูดถึงที่นี่ในฟอรัมออยเลอร์ Project เมื่อประมาณ 4 ปีที่แล้ว แต่เราล้มเหลวในการสร้างอัลกอริทึมพหุนามเวลาที่พิสูจน์ได้ (ในแง่ของN) ดังนั้นฉันจะมอบรางวัล +200 ให้กับผลงานชิ้นแรกที่ประสบความสำเร็จหรือพิสูจน์ความเป็นไปไม่ได้


ฉันใช้เวลากว่าหนึ่งสัปดาห์ในการหาอัลกอริธึมเวลาพหุนามหรือการพิสูจน์ความแข็งแบบ NP โดยใช้การลดลง มีใครที่นี่ทำให้ความคืบหน้าเกี่ยวกับเรื่องนี้?
Enrico Borba

คำตอบ:


4

Brachylogขนาด 28 ไบต์

⟦₁⊇ᶠk⊇pSs₂ᶠ{c≠&⟨+/l⟩ᵐ<ᵈ}ᵐ∧Sl

ลองออนไลน์!

นี่มันช้าจริงๆ ใช้เวลาประมาณ 30 วินาทีN = 3และมันไม่เสร็จสมบูรณ์หลังจาก 12 N = 4นาที

คำอธิบาย

⟦₁                             Take the range [1, …, Input]
  ⊇ᶠk                          Find all ordered subsets of that range, minus the empty set
     ⊇                         Take an ordered subset of these subsets
      pS                       Take a permutation of that subset and call it S
       Ss₂ᶠ                    Find all substrings of 2 consecutive elements in S
           {           }ᵐ      Map for each of these substrings:
            c≠                   All elements from both sets must be different
              &⟨+/l⟩ᵐ            And the average of both sets (⟨xyz⟩ is a fork like in APL)
                     <ᵈ          Must be in strictly increasing order
                         ∧Sl   If all of this succeeds, the output is the length of L.

รุ่นที่เร็วกว่า 39 ไบต์

⟦₁⊇ᶠk⊇{⟨+/l⟩/₁/₁}ᵒSs₂ᶠ{c≠&⟨+/l⟩ᵐ<₁}ᵐ∧Sl

นี้จะใช้เวลาประมาณ 50 N = 4วินาทีบนคอมพิวเตอร์ของฉัน

นี่เป็นโปรแกรมเดียวกันยกเว้นเราเรียงลำดับชุดย่อยของชุดย่อยตามค่าเฉลี่ยแทนที่จะทำการเรียงสับเปลี่ยนแบบสุ่ม ดังนั้นเราจึงใช้แทน{⟨+/l⟩/₁/₁}ᵒp

{         }ᵒ     Order by:
 ⟨+/l⟩             Average (fork of sum-divide-length)
      /₁/₁         Invert the average twice; this is used to get a float average

เราต้องได้ค่าเฉลี่ยลอยตัวเพราะฉันเพิ่งค้นพบข้อผิดพลาดที่ไร้สาระที่ลอยและจำนวนเต็มไม่ได้เปรียบเทียบตามมูลค่า แต่ตามประเภทที่มีการสั่งซื้อภาคแสดง (นี่คือเหตุผลที่ฉันใช้<ᵈและไม่<₁เปรียบเทียบค่าเฉลี่ยทั้งสอง) เคล็ดลับการผกผันสองครั้งในการทำงาน)


ฉันกำลังวางแผนที่จะทำงานอย่างช้า ๆ เพื่อแก้ปัญหานี้ (ตั้งแต่ @JonathanAllan พูดถึงมันในความคิดเห็นอื่น) แต่ฉันอาจจะมาหลายสัปดาห์ด้วยการทำอะไรแบบนี้! ฉันชอบวิธีที่ (เช่น Brachylog ส่วนใหญ่ตอบ) ในท้ายที่สุดมันก็ดูเหมือนว่าการเรียงคำถามอย่างเรียบร้อย
sundar - Reinstate Monica

@Sundar คุณสามารถกลับมาหามันได้ในภายหลังและพยายามที่จะค้นพบวิธีการแก้ปัญหา!
ทำให้เสียชีวิต

3

CJam (81 ไบต์)

{YY@#(#{{2bW%ee{)*~}%}:Z~{)Z__1b\,d/\a+}%$}%{_,1>{2ew{z~~&!\~=>}%0&!}{,}?},:,:e>}

สาธิตออนไลน์ ควรดำเนินการสำหรับการป้อนข้อมูล4ในเวลาที่เหมาะสม แต่ฉันจะไม่ลองด้วยอินพุตที่สูงขึ้น

การผ่า

{                 e# Declare a block (anonymous function)
  YY@#(#          e# There are 2^N subsets of [0, N), but the empty subset is problematic
                  e# so we calculate 2^(2^N - 1) subsets of the non-empty subsets
  {               e# Map integer to subset of non-empty subsets:
    {             e#   Define a block to map an bitset to its set indices; e.g. 9 => [0 3]
      2bW%ee      e#     Convert to base 2, reverse, and index
      {)*~}%      e#     If the bit was set, keep the index
    }:Z           e#   Assign the block to variable Z
    ~             e#   Evaluate it
    {             e#   Map those indices to non-empty subsets of [0, N):
      )Z          e#     Increment (to skip the empty set) and apply Z
      __1b\,d/    e#     Sum one copy, take length of another, divide for average
      \a+         e#     Wrap the subset and prepend its average value
    }%
    $             e#   Sort (lexicographically, so by average value)
  }%
  {               e# Filter out subsets of subsets with conflicts:
    _,1>{         e#   If the length is greater than 1
      2ew         e#     Take each consecutive pair of subsets
      {           e#     Map:
        z~        e#       Zip and expand to get [score1 score2] [subset1 subset2]
        ~&!\      e#       No element in common => 1
        ~=        e#       Different scores => 0
        >         e#       1 iff both constraints are met
      }%
      0&!         e#     1 iff no consecutive pair failed the test
    }{
      ,           e#   Otherwise filter to those of length 1
    }?
  },
  :,:e>           e# Map to size of subset and take the greatest
}

1

JavaScript (ES6), 175 ไบต์

การค้นหาแบบเรียกซ้ำและค่อนข้างช้า ใช้เวลาประมาณ 15 วินาทีเพื่อคำนวณ 7 คำแรกใน TIO

n=>(a=[...Array(n)].reduce(a=>[...a,...a.map(y=>[x,...y],x=n--)],[[]]),g=(p,b=a,n)=>a.map(a=>(m=a.map(n=>s+=++k*b.includes(n)?g:n,s=k=0)&&s/k)>p&&g(m,a,-~n),r=r>n?r:n))(r=0)|r

ลองออนไลน์!

หรือทดสอบเวอร์ชันที่ดัดแปลงนี้ซึ่งส่งเอาต์พุตลำดับของชุดเพิ่มที่ยาวที่สุดที่ยาวที่สุด

อย่างไร?

อันดับแรกเราคำนวณ powerset ของ{1,2,...,n}a

a = [...Array(n)].reduce(a =>
  [...a, ...a.map(y => [x, ...y], x = n--)],
  [[]]
)

ส่วนที่เรียกซ้ำ:

g = (                         // g = recursive function taking:
  p,                          //   p = previous mean average
  b = a,                      //   b = previous set
  n                           //   n = sequence length
) =>                          //
  a.map(a =>                  // for each set a[] in a[]:
    (m = a.map(n =>           //   for each value n in a[]:
      s +=                    //     update s:
        ++k * b.includes(n) ? //       increment k; if n exists in b[]:
          g                   //         invalidate the result (string / integer --> NaN)
        :                     //       else:
          n,                  //         add n to s
      s = k = 0)              //     start with s = k = 0; end of inner map()
      && s / k                //   m = s / k = new mean average
    ) > p                     //   if it's greater than the previous one,
    && g(m, a, -~n),          //   do a recursive call with (m, a, n + 1)
    r = r > n ? r : n         //   keep track of the greatest length in r = max(r, n)
  )                           // end of outer map()

1

งูหลาม 3 , 205 197 184 182 ไบต์

  • ที่บันทึกไว้แปดยี่สิบเอ็ดไบต์ขอบคุณที่OVS
  • บันทึกสองไบต์ด้วย ceilingcat
f=lambda N,c=[[1]]:max([len(c)]+[f(N,c+[n])for k in range(N)for n in combinations(range(1,N+1),k+1)if not{*c[-1]}&{*n}and sum(c[-1])/len(c[-1])<sum(n)/len(n)]);from itertools import*

ลองออนไลน์!


197 ไบต์ใช้แทนsum chain.from_iterable
ovs

@ceilingcat ขอบคุณ
Jonathan Frech
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.