CJam ( 58 56 karakter)
Beberapa karakter tidak dapat dicetak, dan satu adalah tab yang akan dikacaukan oleh perangkat lunak StackExchange:
"¶3¬î¿Á· 7ÛÈmÈÚÚ¡"256b454b212f-{__W%.*A<1b+}qi*-4=
Demo online . Ini akan berjalan online untuk n = 400 dalam waktu sekitar tiga detik.
Dikodekan oleh xxd
:
0000000: 22b6 0233 93ac eebf c1b7 0609 3794 dbc8 "..3........7...
0000010: 6dc8 1015 dada a122 3235 3662 3435 3462 m......"256b454b
0000020: 3231 3266 2d7b 5f5f 5725 2e2a 413c 3162 212f-{__W%.*A<1b
0000030: 2b7d 7169 2a2d 343d +}qi*-4=
Penjelasan
Tangga Möbius pada dasarnya adalah tangga dengan dua sisi tambahan. Mengingat hutan terbatas di tangga, dapat diangkat ke antara 1 dan 4 hutan terbatas di tangga Möbius. Tepi dapat ditambahkan asalkan tidak membuat simpul derajat 3 atau siklus. Derajat keempat sudut dan interkoneksi mereka membentuk 116 kelas hutan terbatas pada tangga, meskipun beberapa di antaranya setara karena simetri persegi panjang. Saya menulis sebuah program untuk menganalisis ekstensi dari sebuah tangga dengan panjang n ke salah satu dari panjang n + 1, dan kemudian menggabungkan kelas menjadi 26 kelas kesetaraan. Ini memberikan formulir tertutup
⎡⎣⎢⎢⎢1111⎤⎦⎥⎥⎥T⎡⎣⎢⎢⎢1120223021410110⎤⎦⎥⎥⎥n−2⎡⎣⎢⎢⎢0100⎤⎦⎥⎥⎥+
⎡⎣⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢221111122⎤⎦⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥T⎡⎣⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢210001030100001020112100120100010011101100010110000020100000010110001140100011122⎤⎦⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥n−2⎡⎣⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢002200000⎤⎦⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥+
⎡⎣⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢1244113222344⎤⎦⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥T⎡⎣⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢0001001000000021001011000200200002000031004001002000011000001000100100000000010003002002000001000010000200101000000110002001001000101020000012100101101000220010010200004⎤⎦⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥n−2⎡⎣⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢1011201000121⎤⎦⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥
so values can be computed fast by taking three linear recurrences and then adding them, but this isn't looking very golfy.
However, if we take the irreducible factors of the various characteristic polynomials and multiply together one of each (ignoring multiplicity) we get a polynomial of degree 10 which gives a working single linear recurrence.
Constructive approach (58 chars)
qi:Q2*,Wa*e!{Wa/{_W%e<}%$}%_&{{,1>},2few:~{:-z(Q(%}%0-!},,
Online demo. It will run online for n=2
without problems and for n=3
with a bit of patience. For n=1
it crashes, but since OP has chosen to exclude that case from the requirements it's not a fundamental problem.
Dissection
qi:Q e# Take input from stdin, parse to int, store in Q
2*,Wa*e! e# Take all permutations of (0, -1, 1, -1, 2, -1, ..., -1, 2*Q-1)
{ e# Map to canonical form...
Wa/ e# Split around the -1s
{_W%e<}% e# Reverse paths where necessary to get a canonical form
$ e# Sort paths
}%
_& e# Filter to distinct path sets
{ e# Filter to path sets with valid paths:
{,1>}, e# Ignore paths with fewer than two elements (can't be invalid; break 2ew)
2few:~ e# Break paths into their edges
{:-z(Q(%}% e# The difference between the endpoints of an edge should be +/-1 or Q (mod 2Q)
e# So their absolute values should be 1, Q, 2Q-1.
e# d => (abs(d)-1) % (Q-1) maps those differences, and no other possible ones, to 0
e# NB {:-zQ(%}% to map them all to 1 would save a byte, but wouldn't work for Q=2
0-! e# Test that all values obtained are 0
},
, e# Count the filtered distinct path sets
A more efficient version takes 98 bytes:
qi2*:Q{a{__0=[1Q2/Q(]f+Qf%_&1$-\f{+E}~}:E~}/]{_W%>!},:MW=0{_{M\f{__3$_@&@:e<@|^{=}{^j}?}1b}{,)}?}j
Online demo
This builds the possible paths by depth-first search, then uses a memoised function which counts the possible restricted forests for a given set of vertices. The function works recursively on the basis that any restricted forest for a given non-empty set of vertices consists of a path containing the smallest vertex and a restricted forest covering the vertices not in that path.
34, 241, 1582, 10204, 65197, 415076, 2638366, 16759249, 106427154, 675771276, 4290678337
. Saya tidak yakin mengapa input1
juga tidak diperlukan, dengan output2
.