Az alábbi letöltési lehetőségek közül választhatsz: (
segítség)
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: utf-8
Méret: 10 KB
using System;
using System.Collections.Generic;
using System.IO;
using System.Collections;
namespace szinesko
{
class Program
{
public static List<kosor> feladatok=new List<kosor>();
public class kosor
{
public byte n;
public byte s;
public byte[] k;
public kosor(byte n, byte s)
{
this.n=n;
this.s=s;
k=new byte[n];
}
}
public static void Main(string[] args)
{
beolvas("stones.in");
int[] m=new int[feladatok.Count];
for(int p=0; p!=feladatok.Count; p++) m[p]=munkaLinear(feladatok[p]);
kiir("stones.out", m);
}
#region "régi"
#endregion
public static byte hatvany(byte kit)
{
if (kit==0) return 1;
return (byte)(hatvany((byte)(kit-1))*2);
}
public struct prefix
{
public byte s, l, h, i;
}
public class prefixTomb
{
private byte[,,,] p;
public prefixTomb(byte szinekszama, byte maxhossz)
{
p=new byte[hatvany(szinekszama), szinekszama, maxhossz, maxhossz];
for (int i=0; i!=hatvany(szinekszama); i++)
for(int j=0; j!=szinekszama; j++)
for(int k=0; k!=maxhossz; k++)
for(int l=0; l!=maxhossz; l++)
p[i,j,k,l]=255;
}
public void setPrefix(prefix P, byte opt)
{
p[P.s, P.l, P.h, P.i]=opt;
}
public byte getPrefix(prefix P)
{
if (P.l!=255) return p[P.s, P.l, P.h, P.i];
return 255;
}
}
static prefixTomb pp;
static kosor q;
public static byte munkaLinear(kosor f)
{
pp=new prefixTomb((byte)f.s, (byte)f.n);
q=f;
prefix u=new prefix();
u.s=0;
u.i=0;
u.l=0;
u.h=0;
byte min=opt(u);
Console.WriteLine(min);
return min;
}
public static byte opt(prefix p)
{
if (p.i>q.n-1) return (byte)(q.n-p.h);
byte ccc=pp.getPrefix(p); if (ccc!=255) return ccc;
byte o1=byte.MaxValue;
if (!((hatvany(q.k[p.i]) | p.s)==p.s) || (q.k[p.i]==p.l))
{
prefix p2=p;
p2.s|=hatvany(q.k[p.i]);
p2.l=q.k[p.i];
p2.h++;
p2.i++;
o1=opt(p2);
}
p.i++;
byte o2=opt(p);
p.i--;
if (o2<o1) o1=o2;
pp.setPrefix(p, o1);
return o1;
}
public static void kiir(string oup, int[] m)
{
TextWriter tw=new StreamWriter(oup);
for (int i=0; i!=m.Length; i++) tw.WriteLine(m[i].ToString());
tw.Close();
}
public static void beolvas(string inp)
{
TextReader tr=new StreamReader(inp);
string sor;
string[] sorok;
while ((sor=tr.ReadLine())!="0 0")
{
sorok=sor.Split(' ');
kosor f=new kosor(Convert.ToByte(sorok[0]),Convert.ToByte(sorok[1]));
sorok=tr.ReadLine().Split(' ');
feladatok.Add(f);
for (int i=0; i!=f.n; i++) f.k[i]=(byte)(Convert.ToByte(sorok[i])-1);
}
tr.Close();
}
}
}