2009年9月4日金曜日

Google Code Jam 2009 C C#でといてみた

正直、これで解けるんだと感動。
DPはすごいな。
というか数列か。

class C
{
int NM;
public void Run()
{
List res = new List();
int line = 0;
//var ss = File.ReadAllLines("C-small-attempt0.in");
var ss = File.ReadAllLines("testcc.txt");
NM = ss[0].ToInt();
line++;
for (int i = 0; i <>
{
var str = ss[line];
var mon = "welcome to code jam";
line++;
var len = str.Length;
var total = new int[mon.Length, len];
for (int k = 0; k <>
{
total[0, k] = str.Substring(0, k + 1).ToCharArray().Count(x => x == 'w');
}
for (int j = 1; j <>
{
total[j, 0] = 0;
}
for (int j = 1; j <>
{
var sm = mon.Substring(0, j + 1);
for (int k = 1; k <>
{
var sstr = str.Substring(0, k + 1);

int r = total[j, k - 1];
if (str[k] == mon[j])
{
r += total[j - 1, k - 1];
}
total[j, k] = r % 10000;
}
}

res.Add("Case #{0}: {1}".FormatWith(i + 1, total[mon.Length - 1, str.Length - 1].ToString().PadLeft(4, '0')));
}
File.WriteAllLines("Ans.txt", res.ToArray());
Console.Write(res.ToArray().Join(Environment.NewLine));
Console.ReadKey();
}
}

0 件のコメント: