Add tags

Add tags to the following comment

再帰&yieldで n=50で204226件、3375 msでした。

Core2 Duo 6300 @ 1.86GHz, WinXP Pro, VS2005

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
using System;
using System.Collections.Generic;

class Program {
    static IEnumerable<string> Young2(int n, int m) {
        if (n <= m) yield return new string('□', n) + '\n';

        for (int i = Math.Min(n - 1, m); i > 0; i--)
            foreach (string s in Young2(n - i, i))
                yield return new string('□', i) + '\n' + s;
    }
    static IEnumerable<string> Young(int n) {
        return (n <= 0) ? new string[] {} : Young2(n, n);
    }
    static void Main(string[] args) {
        foreach (string s in Young(50))
            Console.WriteLine(s);
    }   
}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...