follow is my code. C#, good luck.
I failed for this problem. because my english is poor,
I haven't realy understand some sentence.
so, I've not write " times = times % 10000;".
using System;
using System.Collections.Generic;
using System.Text;
namespace Contest2009RoundC
{
public class CaseItem
{
public const string std = "welcome to code jam";
string source;
int __times;
private int index;
public CaseItem(int index, string s)
{
this.source = s;
this.index = index;
}
//
//
// f(p_start, c_start) = f(p1, c_start - 1) + f(p2, c_start - 1)
+ ... + f(px, c_start - 1)
//
// where pi filter with std[c_start] = source[pi].
//
//
public void Cal()
{
if (source.Length == 0)
{
this.__times = 0;
return;
}
int[,] target_times = new int[source.Length, std.Length];
for (int p_start = 0; p_start < source.Length; p_start++)
{
for (int c_start = 0; c_start < std.Length; c_start++)
{
target_times[p_start, c_start] = 0;
}
}
if (std[0] == source[0])
{
target_times[0, 0] = 1;
}
for (int p_start = 1; p_start < source.Length; p_start++)
{
char c = std[0];
if (source[p_start] == c)
{
target_times[p_start, 0] = target_times[p_start - 1, 0]
+ 1;
}
else
{
target_times[p_start, 0] = target_times[p_start - 1, 0];
}
target_times[p_start, 0] = target_times[p_start, 0] % 10000;
}
for (int p_start = 1; p_start < source.Length; p_start++)
{
for (int c_start = 1; c_start < std.Length; c_start++)
{
int times = 0;
char c = std[c_start];
for (int index = c_start; index <= p_start; index++)
{
if (c == source[index])
{
times = times + target_times[index - 1, c_start
- 1];
times = times % 10000;
}
}
target_times[p_start, c_start] = times;
}
}
this.__times = target_times[source.Length - 1, std.Length - 1];
//using (System.IO.StreamWriter sw = new System.IO.StreamWriter(
// string.Format("b{0}.txt", this.index)))
//{
// for (int i = 0; i < source.Length; i++)
// {
// for (int j = 0; j < std.Length; j++)
// {
// if (target_times[i, j] > 0)
// {
// sw.Write("{0:D3} ", target_times[i, j]);
// }
// else
// {
// sw.Write(" ");
// }
// }
// sw.WriteLine();
// }
//}
}
public string GetTimes()
{
if (this.__times < 10)
{
return "000" + this.__times.ToString();
}
else if (this.__times < 100)
{
return "00" + this.__times.ToString();
}
else if (this.__times < 1000)
{
return "0" + __times.ToString();
}
else
{
return __times.ToString();
}
}
}
public class Round
{
public List<CaseItem> items;
private void Read()
{
string filepath = @"a.in";
using (System.IO.StreamReader sr = new
System.IO.StreamReader(filepath))
{
string first_line = sr.ReadLine();
int num = int.Parse(first_line);
items = new List<CaseItem>(num);
for (int mi = 0; mi < num; mi++)
{
items.Add(new CaseItem(mi, sr.ReadLine()));
}
}
}
private void Cal()
{
foreach (CaseItem item in items)
{
item.Cal();
}
}
private void Write()
{
string filepath = @"out.txt";
using (System.IO.StreamWriter sw = new
System.IO.StreamWriter(filepath, false,
System.Text.Encoding.ASCII))
{
for (int i = 0; i < items.Count; i++ )
{
CaseItem item = items[i];
sw.WriteLine("Case #{0}: {1}", i + 1, item.GetTimes());
}
}
}
public void Execute()
{
this.Read();
this.Cal();
this.Write();
}
}
public class Program
{
static void Main(string[] args)
{
(new Round()).Execute();
}
}
}
2009/9/4 ashish khurana <[email protected]>
> Can anyone post the correct answer for the following string for the
> "welcome to code jam problem"
>
>
> zdc lmcwowmwwwwwhwwajemoeewcecmeedeeoooll lllolell pjccdccccccccc ooo
> ctoooowlommmomodmemmmemtmecmeeewelojoewe ome d cc ce ttm otoctwmtjmwt
> ootoooo ocagm m lco e cccc o owcocccoowcocoejaddodoodeoemddooe ddcedoda
> eeedclejoaeemew l e c ewajjlejdmjjjjjjdeoaaaaaoadaoa aa aeeom wommmomeme
> ewmedcmv
>
>
> My program is correct but it's taking a hell lot of time, wanna confirm the
> answer.
>
> Thanks
> hangovercoder :)
>
> >
>
--
--咖啡猫--
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"google-codejam" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-code?hl=en
-~----------~----~----~----~------~----~------~--~---