ãã ããå±ã®ã²ã¾ã¤ã¶ããã¨ã¯
ãããã¤ã®å¡ãã®æ´¾çåã®ãããªããºã«ã
é«ã3ã®ä¸²ã3æ¬ããã3è²ã®å£å2åãã¤è¨6åãåºãã£ã¦ããããããã1åãã¤ç§»ãæ¿ãã¦ãããç¶æ
ããããç¶æ
ã¸ã¨é·ç§»ããããã¨ããã²ã¼ã ã
- 移åã§ããã®ã¯å串ã§ä¸çªä¸ã«ããå£åã ãã
- å£åã®å¤§ããã®ãããªæ¦å¿µã¯ãªããé«ã3以å
ã§ããã°ã©ãã«ã§ãåãããã
åç´ãªã«ã¼ã«ã ããªããªãã«å¥¥ãæ·±ãããã£ããèãã¦åãããªãã¨æé©ãªæé ã§éæããã®ã¯æå¤ã«é£ããã
ããºã«ãªã¼ãã£ã·ã§ã³ã¨ãããã®ã§æåªç§è³ãåè³ããä½åãããã
www.jpuzzle.jp
ããããã§ããåååããããã®ãã®ããã ã
æé·æé ã®åé¡ã¯â¦ï¼
ãã ããå±ã®ã²ã¾ã¤ã¶ããã®ä¸ã«ã¯åé¡éãå梱ããã¦ãããå§ç¹ã¨çµç¹ãæå®ããå
¨52åã®åé¡ãåé²ããã¦ãããåºç¤ã®ãåç´ãã¯æç5ã6æç¨åº¦ã ããæå¾ã®ãç¹ç´ãã¯æçã§ã14æã®æé ãå¿
è¦ãªãã®ã¨ãªã£ã¦ããã
ããã§çåã湧ããã®ã§èãã¦ã¿ããã¨ã«ããã
ãã ããå±ã®ã²ã¾ã¤ã¶ããã¨ããããºã«ã妻ãè¦ã¤ãã¦ãé¢ç½ããã ã£ãã®ã§è²·ã£ã¦ã¿ãã(ç¥è²ã«ããªãããªï¼ã¨æã£ããåã©ããã¡ã¯å£åãã¶ãæãã¦éã¶ã ãã ã£ãâ¦ã)
be-en.co.jp/products/bog...
ã«ã¼ã«ã¯ç°¡åã§ãé«ã3ã®3æ¬ã®ä¸²ã«ç©ã¾ãã2åãã¤3è²ã®ã ãããã1åãã¤ä»ã®ä¸²ã«ç§»åã㦠ããç¶æ
ããããç¶æ
ã«å¤ããããããã¨ãããã®ãå梱ã®åé¡éã«ã¯é£æ度ãã¨ã«52åã®ãã®ãè¼ã£ã¦ããã
æé«é£åº¦ã®ãã®ã¯14æãã ã£ãã®ã ã æããã¦ãããæé·ãªã®ã ãããï¼ã¨ããçåã湧ããã®ã§èãã¦ã¿ããã
[image or embed]
— ãããã¼ã (@sugyan.com) October 9, 2024 at 10:20 PM
çµã¿åãããã°ã©ãåé¡
ã¾ãããã®ã(é«ã3)Ã(3æ¬)ã®ä¸²ã«ã(3è²)ã®å£å(2å)ãã¤ãç©ããã¨ããæ¡ä»¶ã§ãä½ç¨®é¡ã®ç¶æ
ãããããèããã
ã ããã®æ°ã®é
ç½®ã ããèããã¨ãå·¦ãã [3, 3, 0]
ã®ä»ã
[3, 0, 3]
, [0, 3, 3]
ã®2æ¬ãåã¾ã£ã¦1æ¬ã空ã®ãã¿ã¼ã³
[2, 2, 2]
ã®åæ°ã§åã¾ã£ã¦ãããã¿ã¼ã³
[3, 2, 1]
, [2, 3, 1]
, ... ã®ãããªãã¿ã¼ã³ å
¨6éã
ã§åè¨ 10éã ãåå¨ãããã¨ãããã«ãããã
(ã¡ãªã¿ã«åé¡éã§ã¯ æå¾ã® [3, 2, 1]
ã®ãããªãã¿ã¼ã³ãå§ç¹ã»çµç¹ã«æå®ããããã®ã¯åå¨ãã¦ããªã)
次ã«6åã®å£åã®ä¸¦ã³æ¹ãèããã
æåã®è²ã§6åã®ãã¡2åãé¸ã¶ã®ã 6C2 = 15
éãã次ã®è²ã§æ®ã£ã4åãã2åãé¸ã¶ã®ã 4C2 = 6
éããæå¾ã®è²ã¯ 2C2 = 1
éãã§ãããããæãåããã 15 * 6 * 1 = 90
éããåå¨ããã
ãã£ã¦ãããããã®é
ç½®ãã¿ã¼ã³10éãã«ããããã90éãã®ä¸¦ã³æ¹ãåå¨ããã®ã§ãæãå¾ãç¶æ
ã®çµã¿åããã¯å
¨é¨ã§ 900éã ã¨ãªãã
ããç¶æ
ããå£åãä»ã®ä¸²ã¸ç§»åããæä½ã¯ããã®900éãããä¸ã§å¥ã®ç¶æ
ã¸ã¨é·ç§»ããæä½ãã¨ãããã¨ã«ãªãã1åã®æä½ã§é·ç§»ã§ããç¶æ
å士ã辺ã¨ãã¦ç¹ããã¨ã§ã900é ç¹ã®ç¡åã°ã©ããæ§ç¯ãããã¨ãã§ããã
ããããã¨ããããç¶æ
ããããç¶æ
ã¸é·ç§»ãããæçã®æé ãã¯ããã®ã°ã©ãä¸ã§ã®æççµè·¯ãæ±ãããã¨ã«ç¸å½ããã
ã¨ãããã¨ã§ããã®ããºã«ã®åé¡ã®æé©è§£ã®å°åºã¯ãã¹ã¦ã°ã©ãä¸ã§ã®æççµè·¯åé¡ã§ãããæé·æé ã®åé¡ãèããã®ã¯ããã®ã°ã©ãã®ãç´å¾ããæ±ãããã¨ã«ç¸å½ããã
ããã°ã©ã ã§è§£ã
æççµè·¯ãæ±ããã°ã©ãåé¡ã¨åããã°ãããã°ã©ã ã§ç°¡åã«è§£ããã¨ãã§ããã
ç¶æ
ã®åæ
ã¾ãã¯ã900éãã®å
¨ç¶æ
ãåæããã
並ã³æ¿ãã®åæã¯ãããã§ã¯åè²ã®ãã®ãåºå¥ããªããããå
ã«ããããã®åæ°ãã«ã¦ã³ããã¦ããã¦ããããã使ã£ã¦backtrackingã§åæããã
use std::collections::BTreeMap;
pub fn unique_permutations(elems: Vec<u8>) -> Vec<Vec<u8>> {
fn backtrack(
n: usize,
curr: &mut Vec<u8>,
counts: &mut BTreeMap<u8, u32>,
result: &mut Vec<Vec<u8>>,
) {
if n == 0 {
return result.push(curr.clone());
}
for key in counts.keys().copied().collect::<Vec<_>>() {
if counts[&key] == 0 {
continue;
}
counts.entry(key).and_modify(|e| *e -= 1);
curr.push(key);
backtrack(n - 1, curr, counts, result);
curr.pop();
counts.entry(key).and_modify(|e| *e += 1);
}
}
let mut result = Vec::new();
let mut counts = BTreeMap::new();
for &elem in &elems {
*counts.entry(elem).or_insert(0) += 1;
}
backtrack(
elems.len(),
&mut Vec::with_capacity(elems.len()),
&mut counts,
&mut result,
);
result
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_unique_permutations() {
let perms = unique_permutations(vec![1, 1, 2, 2, 3, 3]);
assert_eq!(perms.len(), 90);
}
}
ããã¦ãé
ç½®åæ°ã®ãã¿ã¼ã³ã¯ä¸éã¤ãã®æ´æ°åå²ã®åæã¨ãªãããã¡ãã¯backtrackingããã¾ã§ããªãã®ã§å帰é¢æ°ã ãã§åæããã
pub fn bounded_partitions(len: usize, upper_limit: u32, target_sum: u32) -> Vec<Vec<u32>> {
fn recursive(
i: usize,
upper_limit: u32,
remain: u32,
curr: &mut Vec<u32>,
results: &mut Vec<Vec<u32>>,
) {
if i == 0 {
if remain == 0 {
results.push(curr.clone());
}
return;
}
for n in 0..=upper_limit.min(remain) {
curr[i - 1] = n;
recursive(i - 1, upper_limit, remain - n, curr, results);
}
}
let mut results = Vec::new();
recursive(
len,
upper_limit,
target_sum,
&mut vec![0; len],
&mut results,
);
results
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_bounded_partitions() {
let partitions = bounded_partitions(3, 3, 6);
assert_eq!(partitions.len(), 10);
}
}
ããã§ããããåæã§ããã®ã§ããã¨ã¯ããããçµã¿åããã¦å並ã³æãããåé
ç½®ãã¿ã¼ã³ãé©ç¨ããã
let permutations = unique_permutations(vec![1, 1, 2, 2, 3, 3]);
for stacks in bounded_partitions(3, 3, 6)
.iter()
.flat_map(|partition| {
permutations.iter().map(|p| {
let mut stacks = vec![Vec::new(); 3];
let mut iter = p.iter();
for (i, num) in partition.iter().enumerate() {
for _ in 0..*num {
stacks[i].push(*iter.next().unwrap());
}
}
stacks
})
})
{
println!("{:?}", stacks);
}
ããã§900éãã®ç¶æ
ãå
¨åæã§ããã
[[1, 1, 2], [2, 3, 3], []]
[[1, 1, 2], [3, 2, 3], []]
[[1, 1, 2], [3, 3, 2], []]
[[1, 1, 3], [2, 2, 3], []]
[[1, 1, 3], [2, 3, 2], []]
[[1, 1, 3], [3, 2, 2], []]
[[1, 2, 1], [2, 3, 3], []]
[[1, 2, 1], [3, 2, 3], []]
[[1, 2, 1], [3, 3, 2], []]
[[1, 2, 2], [1, 3, 3], []]
[[1, 2, 2], [3, 1, 3], []]
[[1, 2, 2], [3, 3, 1], []]
...
ã¡ãªã¿ã« Pythonãªã itertools
ã¨ãã使ã£ã¦3è¡ãããã§å
¨åæã§ãããã
>>> from itertools import islice, permutations, product, repeat
>>> for perm, part in product(sorted(set(permutations([1, 1, 2, 2, 3, 3]))), (a for a in product(*repeat(range(4), 3)) if sum(a) == 6)):
... it=iter(perm)
... print(*tuple(list(islice(it, n)) for n in part))
...
[] [1, 1, 2] [2, 3, 3]
[1] [1, 2] [2, 3, 3]
[1] [1, 2, 2] [3, 3]
[1, 1] [2] [2, 3, 3]
[1, 1] [2, 2] [3, 3]
[1, 1] [2, 2, 3] [3]
[1, 1, 2] [] [2, 3, 3]
[1, 1, 2] [2] [3, 3]
[1, 1, 2] [2, 3] [3]
[1, 1, 2] [2, 3, 3] []
[] [1, 1, 2] [3, 2, 3]
[1] [1, 2] [3, 2, 3]
[1] [1, 2, 3] [2, 3]
...
ã°ã©ãã®æ§ç¯
次ã«ãåç¶æ
éã®é·ç§»ã辺ã¨ããã°ã©ãã®æ§ç¯ãèããã
Vec
ãstackã¨ãã¦å©ç¨ãã¦ã空ã§ãªãstackãã1㤠pop
ã㦠ãã®è¦ç´ ãé«ããä¸éã«éããªãä»ã®stack㸠push
ãããã¨ããæä½ã§é·ç§»å
ã®ç¶æ
ãå¾ããããå
¨ç¶æ
ã«å¯¾ãã¦å¯è½ãªå
¨é·ç§»ãåæããå¿
è¦ããããã1ç¶æ
ããé·ç§»å¯è½ãªã®ã¯ç§»åå
ã®ä¸²ã®é¸æè¢ã3æ¬ã§ç§»åå
ãã®é¸æè¢ãæ®ã2æ¬ãªã®ã§é«ã
6éãã
#[derive(Hash, Eq, PartialEq)]
struct State([Vec<u8>; 3]);
impl State {
pub fn next_states(&self, max_len: usize) -> Vec<Self> {
let mut results = Vec::new();
for i in 0..3 {
for j in 0..3 {
if i == j || self.0[i].is_empty() || self.0[j].len() == max_len {
continue;
}
let mut v = self.0.clone();
let ball = v[i].pop().unwrap();
v[j].push(ball);
results.push(Self(v));
}
}
results
}
}
ãã¨ã¯å
¨900éãã®ç¶æ
ã«æ¯ã£ãindexã使ã£ã¦ãããããã®ç¶æ
ããé·ç§»å¯è½ãªç¶æ
ã®indexã®é
åãæã¤ããã«ãã¦ããã¨ããã®å¾ã®è¨ç®ã楽ã«ãªãã
use std::collections::HashMap;
struct Graph {
nodes: Vec<State>,
edges: Vec<Vec<usize>>,
}
impl Graph {
pub fn new(nodes: Vec<State>, max_len: usize) -> Self {
let mut edges = vec![Vec::with_capacity(6); nodes.len()];
let node_map = nodes
.iter()
.enumerate()
.map(|(i, node)| (node, i))
.collect::<HashMap<_, _>>();
for src in &nodes {
for dst in src.next_state(max_len) {
edges[node_map[src]].push(node_map[&dst]);
}
}
Self { nodes, edges }
}
}
ããã§ã 900é ç¹ 3,240辺ã®ã°ã©ããæ§ç¯ã§ããã
æççµè·¯åé¡ã解ã
ãã¨ã¯ãæå㪠Dijkstra's algorithm ã使ãã°ãä»»æã®å§ç¹ããåé ç¹ã¸ã®æçè·é¢(ã¨ãã®çµè·¯ã)ãæ±ãããã¨ãã§ããã
use std::cmp::Reverse;
use std::collections::BinaryHeap;
impl Graph {
fn distances(&self, src: usize) -> Vec<Option<u32>> {
let mut distances = vec![None; self.nodes.len()];
let mut bh = BinaryHeap::new();
distances[src] = Some(0);
bh.push((Reverse(0), src));
while let Some((Reverse(d), i)) = bh.pop() {
for &j in &self.edges[i] {
if distances[j].is_none() {
distances[j] = Some(d + 1);
bh.push((Reverse(d + 1), j));
}
}
}
distances
}
}
ã°ã©ãã®ç´å¾ãããªãã¡å
¨é ç¹å¯¾ã«å¯¾ããæççµè·¯ã®ãã¡æé·ã®ãã®ããæ±ããã«ã¯ FloydâWarshall algorithm ãããç¥ããã¦ããã¨æããããã®ã°ã©ãã®å ´åã¯é ç¹æ°ã«å¯¾ãã¦è¾ºæ°ãå°ãªããªã®ã§ãå
¨é ç¹ãå§ç¹ã¨ãã¦Dijkstraã使ã£ãæ¹ããããè¨ç®éã¯å°ãªãããã ã£ãã
ã©ã¡ãã«ãããã®ç¨åº¦ã®è¦æ¨¡ãªãæå
ã®PCã§ãååã«éãã900 * 900 = 810,000
éãã®ãã¹ã¦ã®å§ç¹ã»çµç¹ã®çµã¿åããã§ã®æçè·é¢ãæ±ããã®ã« 50msç¨åº¦ã§è¨ç®ãçµããã
ããã¦ä»¥ä¸ã®ãããªçµæãå¾ãããã
distance 0: 900
distance 1: 3240
distance 2: 7128
distance 3: 13716
distance 4: 21924
distance 5: 32544
distance 6: 48636
distance 7: 72684
distance 8: 90162
distance 9: 99990
distance 10: 115788
distance 11: 108144
distance 12: 88266
distance 13: 66816
distance 14: 33618
distance 15: 6264
distance 16: 180
total: 810000
ã¨ãããã¨ã§ãæçæé ã16æã®çµã¿åãããåå¨ãããã¨ãåãã£ãã
WASMåãã¦ããã©ã¦ã¶ä¸ã§è§£ã
ãã®ç¨åº¦ã®è¨ç®éãªãJavaScriptã§æ¸ãã¦ããããªãã«éãåãã¨ã¯æããããã£ããRustã§æ¸ããã®ã§ wasm-pack ã使ã£ã¦WASMã«ãã¦ããã©ã¦ã¶ä¸ã§åããã¦ã¿ããã¨ã«ããã
å§ç¹ã¨çµç¹ããã©ãã°&ããããã§ç·¨éããã¨ãç¬æã«æçæé ã解ãã¦ç¤ºãã¦ããããURLã®queryã§æå®ãã§ããã
ä¾ãã°ãæé·ã®16æã®åé¡ã¨ãã®æç解ã®ä¾ã
WASMããã¼ããã¦ã°ã©ãã¾ã§æ§ç¯ãã¦ãã¾ãã°ãå§ç¹æå®ãã¦ã®Dijkstraã¯ç¾Î¼sç¨åº¦ã§æ¢ç´¢ã§ããã®ã§WebWorkerãªã©ã«ç§»è²ããå¿
è¦ããç¡ãã
ånodeã¸ã®æçè·é¢ãè¨ç®ããéã«é·ç§»å
ã®nodeæ
å ±ãè¨é²ãã¦ããã°ãå帰çã«éã«è¾¿ããã¨ã§çµè·¯ã(ããã¾ã§1ä¾ã ã)æ±ãããã¨ãã§ããã
ããããã¹ã¦ç°ãªãå£åã ã£ãã
ããããã¯ãã ããå±ã®ã²ã¾ã¤ã¶ããããé¢ãã¦èãã¦ããã
ã3è²ã®å£å2åãã¤è¨6åãã¨ããæ¡ä»¶ã§è¨ç®ãã¦ãããããããããããã¹ã¦ç°ãªã6è²ãã«å¡ãåãããã¦ãããã®ã ã£ããã©ããªãã ãããã
å£åã®ç·æ°ã¯å¤ãããªãã®ã§é
ç½®ãã¿ã¼ã³ã¯åã10éãã ãã並ã¹æ¿ãã®åæã 6C2 * 4C2 * 2C2 = 15 * 6 * 1 = 90
éãã ã£ãã®ãã 6! = 720
éãã«å¢ãããã¨ã«ãªããã¤ã¾ãç¶æ
æ°ã8åã® 7200éã ã«å¢ãããã¨ã«ãªãã
ä¸è¿°ã®ãããªããã°ã©ã ã§è§£ãå ´åã vec![1, 1, 2, 2, 3, 3]
ã¨ãã¦ããå
¥åã vec![1, 2, 3, 4, 5, 6]
ã«å¤ããã ãã§è¯ãã
7,200é ç¹ 25,920辺 ã®ã°ã©ããæ§ç¯ãããæé·19æã®åé¡ãåå¨ãããã¨ãåããã
distance 0: 7200
distance 1: 25920
distance 2: 64800
distance 3: 138240
distance 4: 257040
distance 5: 437760
distance 6: 738720
distance 7: 1311120
distance 8: 2088720
distance 9: 2954880
distance 10: 4080240
distance 11: 5700240
distance 12: 6947280
distance 13: 7223040
distance 14: 7778160
distance 15: 6809760
distance 16: 3745440
distance 17: 1298160
distance 18: 224640
distance 19: 8640
total: 51840000
æé·19æ㯠8,640éããããããå§ç¹ã [[1, 2, 3], [4, 5, 6], []]
ã®ããã«åºå®ããã¨4éãã ãã«çµããããã¨ã¯ãããã®ä¸¦ã³é ãé
ç½®ããã串ãå
¥ãæ¿ããã ãã§æ¬è³ªçã«åãåé¡ã¨ãªãã
ã©ãã1çªä¸ã®å£åå士ãå
¥ãæ¿ããã2段ç®ã«ãã£ããã®ã¯3段ç®ã®ã©ã¡ããã«ã3段ç®ã«ãã£ããã®ã¯2段ç®ã®ã©ã¡ããã«å
¥ãæ¿ãããã¨ããæä½ã®ãã®ã®ããã ã
ããã«ä¸è¬åãã¦ããã¨
ãé«ã3ã®3æ¬ã®ä¸²ã«ãã¨ããæ¡ä»¶ãå¤ãã¦ãã£ã¦ã¿ãã
é«ãH
ã® N
æ¬ã®ä¸²ã«ãH * (N - 1)
è²ã®å£åãç©ããã¨èããã¨ã©ãã ããããä»»æã®ç¶æ
ã«é·ç§»å¯è½ã ãããã
å°éå¯è½æ§
æ大㧠H * N
ã®ç©ºéã¨ãªãããå°ãªãã¨ã H
ååã®ééã¯ãªãã¨ä¸çªä¸ã®å£åã移åãããã¨ãã§ããªãã®ã§ä»»æã®ç¶æ
ã«é·ç§»ãããã¨ã¯ä¸å¯è½ã«ãªãã å£åã¯H * (N - 1)
å以ä¸ã§ãããã¨ã¯å¿
é ã ã
N
㯠3以ä¸ã§ããå¿
è¦ãããããã ããé«ã2
ã§2
æ¬ã§2
è²ã®å£åãã®å ´åãèããã¨æããã«1æ¬ã®ä¸ã§ç©ã¾ãã2è²ã®å£åãå
¥ãæ¿ããæä½ãä¸å¯è½ã3æ¬ããã°ã©ãããéé¿ããã¦å
¥ãæ¿ããæé ãå¯è½ã«ãªãããã (証æã¯ç¥)ã
3æ¬ã使ã£ã¦ä»»æã®ä½ç½®ã®ãã®ãä¸çªä¸ã«æ½ãè¾¼ã¾ããæé ã®åå¨ã示ããã¨ããã§ããã°ããããç¹°ãè¿ããã¨ã§æ®ãã¯é«ãH-1
ã®åé¡ã«å¸°çã§ãããé«ã1ã§3æ¬ãªãæããã«ä»»æã®ç¶æ
ã«é·ç§»å¯è½ãªã®ã§ã帰ç´æ³ã§è¨¼æã§ãããããããªãããããã3æ¬ããã°ã©ããªé«ãã§ãå¯è½ããã
ä»»æã®3æ¬ã®éã§ä»»æã®ç¶æ
ã«é·ç§»å¯è½ã§ããã°ãN+1
æ¬ã«ãªã£ã¦ããã¯ãé·ç§»å¯è½ã«ãªãã¯ãã ã
å¾ã£ã¦ãã¡ããã¨è¨¼æã¯ã§ãã¦ããªããã© ãããããé«ãH
ã® N
æ¬ã®ä¸²ã«ãH * (N - 1)
è²ã®å£åãç©ããã¨ããã«ã¼ã«ã¯ N >= 3
ã§ããã°ä»»æã®ç¶æ
ã«é·ç§»å¯è½ã§ãããã¨ãããã¨ã«ãªãã ããã
é ç¹æ°
ã§ã¯ãããã®å ´åã«ãæãå¾ãç¶æ
ã®ç·æ°ãã¤ã¾ãã°ã©ãã®é ç¹æ°ã¯ã©ããªãã ãããã
å£åã®ä¸¦ã³æ¹ã¯ã éãã N = 3, H = 3
ãªã 6! = 720
éãã ã£ãã
é
ç½®ãã¿ã¼ã³ã¯ãN
æ¬ã®ä¸²ã« H * (N - 1)
åã®å£åãé
ç½®ããå ´åã®ä¸éã¤ãæ´æ°åå²ã®åæã¨ãªãããããã¯éã«H
ååã®ééãã©ã®ä¸²ã«åå²ããããã¨èããæ¹ãç°¡åã
H
åã®ãã®ãN
åã«åå²ããã®ã§ããã°ãN-1
åã®ä»åãã¨H
åã®ééã®ä¸¦ã¹æ¿ãã®æ°ã¨ãªãããã㯠ã¨è¨ç®ã§ããã
ãã£ã¦ãããããæãåããã ãå
¨ç¶æ
æ°ã¨ãªãã
>>> from math import comb, prod
>>> f = lambda n, h: prod(range(1, h * (n - 1) + 1)) * comb(n + h - 1, h)
>>> f(3, 3)
7200
>>> f(3, 4)
604800
N = 3
ãªã
H = 1: 6
H = 2: 144
H = 3: 7,200
H = 4: 604,800
H = 5: 76,204,800
ã¨é«ã5
ã§ããªãã®è¨ç®éã«ãªããã¨ãè¦è¾¼ã¾ããã
N = 4
ã ã¨
H = 1: 24
H = 2: 7,200
H = 3: 7,257,600
H = 4: 16,765,056,000
H = 5: 73,229,764,608,000
N = 5
ã ã¨
H = 1: 120
H = 2: 604,800
H = 3: 16,765,056,000
H = 4: 1,464,595,292,160,000
H = 5: 306,545,653,030,256,640,000
ã¨ãªããé«ã3
ã§ãã¡ãã£ã¨è¨ç®éã大å¤ãªãã¨ã«ãªãããã â¦ãå£åã®åæ°ãå¢ããã¨ã¨ã«ãã大å¤ã
æ°åä¸ã«ãªã£ã¦ããã¨è¨ç®ãå°ãã§ãéããªããã工夫ãå¿
è¦ã§ãè¤æ°ã®Stackã使ããããã«é«ãã8ãè¶
ããªãåæ㧠u64
ã«8bitãã¤è©°ãã¦åºå®æ°ã® u64
é
åã§è¡¨ç¾ããããããããæ ¼ç´ãã HashMap
ãæ¨æºã ã¨é
ãã®ã§ ahash
ã使ã£ã¦é«éåããããã¨ãã£ããã¥ã¼ãã³ã°ãæ½ããã
æ¬æ°ãåºå®ããé«ããå¤ãã
N = 3
ã§åºå®ãã¦ãé«ãH
ãå¤ããã¨ã©ããªãã ãããã
H = 3
ã¯åè¿°ããéãã 7,200é ç¹ 25,920辺 ã®ã°ã©ã㧠19æãæé·ã®åé¡ã ã£ãã
H = 4
ã 㨠604,800é ç¹ 2,419,200辺 ã®ã°ã©ãã«ãªãã
æé·ææ°ã¯ 27æã§ã[[1, 2, 3, 4], [5, 6, 7, 8], []]
ã®ããã«2æ¬ãåãã¦ãããã®ããåãããã¿ã¼ã³ã¯11éãåå¨ããããã ã£ãã
ä¾:
H = 5
ã 㨠76,204,800é ç¹ 326,592,000辺 ã®ã°ã©ãã«ãªãã
æé·ææ°ã¯ 36æã§ãåæ§ã«6éãã»ã©è¦ã¤ããã
ä¾:
ã¡ãã£ã¨æ³åã¯è¦ã¤ãããªãã£ãããå°ãªãã¨ããããã¤ã®å¡ãã®ããã«ææ°é¢æ°çã«ææ°ãå¢ããã¨ãããã¨ã¯ãªãããã ã
é«ããåºå®ããæ¬æ°ãå¤ãã
H = 3
ã ã¨è¨ç®éãè¨å¤§ã«ãªãã®ã§ã H = 2
ã§åºå®ã㦠N
ãå¤ãã¦ã¿ãã
N = 3
ã 㨠144é ç¹ 432辺 ã®ã°ã©ãã«ãªãã æé·ã¯ 10æ ã«ãªãã
N = 4
ã 㨠7,200é ç¹ 34,560辺 ã®ã°ã©ãã«ãªããæé·ã¯ 15æ ã§ããã㯠[[1, 2], [3, 4], [5, 6], []]
ã®ãããªå½¢ã§ã¯ãªã [[1, 2], [3, 4], [5], [6]]
ã®ãããªå½¢ããå§ãããã¿ã¼ã³ã ãã§ç¾ããããã ã
N = 5
ã 㨠604,800é ç¹ 4,032,000é ç¹ ã®ã°ã©ãã«ãªããæé·ã¯ 19æ ã§ãããããã¯ã [[1, 2], [3, 4], [5, 6], [7], [8]]
ã®ãããªå½¢ããã®ãã®ã ã
H = 2, N = 4
㯠H = 3, N = 3
ã¨åãé ç¹æ°ã ãã辺æ°ãå¤ããªãæé·æãçãã
åæ§ã« H = 2, N = 5
ã H = 3, N = 4
ã¨åãé ç¹æ°ã ãã辺æ°ãå¤ããªãæé·æãçããé«ããç¡ãã¶ãæ·±ãæããããªé¢åãªæé ãæ¸ãã ãããããããã¯ãããã
ã¾ã¨ã
- ãã ããå±ã®ã²ã¾ã¤ã¶ããã¨ããé¢ç½ãããºã«ããã
- ã°ã©ãåé¡ã¨ãã¦ããã°ã©ã ã§è§£ããã¨ãã§ãã
- åé¡éã§ã¯14æã®åé¡ãè¼ã£ã¦ãããã16æã®åé¡ãåå¨ãããã¨ãåãã£ã
- Webãã©ã¦ã¶ã§åããä¸ç¬ã§æççµè·¯ãæ±ãããã¨ãã§ãããã®ãä½ã£ã
- å£åã®è²ããã¹ã¦ç°ãªãå ´åã串ãå¢ããå ´åã串ãããé«ããªã£ãå ´åãªã©ã«ã¤ãã¦èå¯ãã
Repository