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: 1 KB
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Tukorszo
{
class Program
{
private string word;
private int[,] cache;
public Program()
{
StreamReader ins = new StreamReader("tukor.bea");
StreamWriter outs = new StreamWriter("tukor.kia");
word = ins.ReadLine();
cache = new int[ word.Length, word.Length ];
for( int i=0; i<word.Length; i++ ) {
for( int j=0; j<word.Length; j++ ) {
cache[i, j] = -1;
}
}
outs.WriteLine( getMaxLength( 0, word.Length-1 ) );
outs.Close();
}
private int getMaxLength( int x, int y )
{
if( x > y ) return 0;
if( x == y ) return 1;
if( cache[x, y] != -1 ) return cache[x, y];
if( word[x] == word[y] ) {
cache[x, y] = getMaxLength( x+1, y-1 )+2;
} else {
cache[x, y] = Math.Max( getMaxLength( x+1, y ), getMaxLength( x, y-1 ) );
}
return cache[x, y];
}
static void Main(string[] args)
{
new Program();
}
}
}