Scrabble Flash
시간 제한4초메모리 제한1024 MB
최대 10개의 짧은 서로 다른 단어와 시간 제한이 주어질 때, 두 연속 단어의 최장 공통 부분 문자열 길이로 정해지는 비용을 고려해 시간 안에 찾을 수 있는 단어 개수의 최댓값을 구한다.
문제
In the game of Scrabble Flash, you are given 5 tiles of letters, and you want to find as many words as you can before time runs out. In our particular version of this game, the letter appearing on a tile can be changed to any other letter of your choice by pressing a button. Some time will need to be spent if you want to change letters, so it is desirable to avoid such changes as much as possible.
Players of this game have noticed that it is much easier to find another word that is similar to the current word than to find another word that is less similar. These players believe they have come up with a formula to estimate the amount of time it takes to find the next word given the word you have most recently found. Let be the length of the the word being found, and be the length of the longest common substring of the two words. They estimate that it takes a person \[ \frac{w (w+1)}{2} - \frac{s(s+1)}{2} \] seconds to find the next word.
Given a list of words, they would like you to find the maximum number of words that can be found in a given number of seconds.
입력
The first line contains two space-separated integers: , the number of seconds, and , the number of words to consider (, ). Following this are lines, each with one word consisting of 1--5 lowercase letters a--z. The first word is the word you start with, and is considered found at 0 seconds. All words are distinct.
출력
Print a single number that is the maximum number of words you can find in the given number of seconds.