#Codeforces 323[div 2]D.Once Again【最適化dp】


タイトル
Once Again
PROBLEM
You are given an array of positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing sequence of the given array.
Input
The first line contains two space-separated integers: n, T (1 ≤ n ≤ 100, 1 ≤ T ≤ 107). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 300).
Output
Print a single number — the length of a sought sequence.
Sample test(s)
input
4 3
3 1 4 2

output
5

Note
The array given in the sample looks like that: 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2. The elements in bold form the largest non-decreasing subsequence.
題目は、100個の乱数の循環T回は1つの数列を形成して、この数列の最長の減少しない子数列を求めます.
循環節Tは数級が大きく,すべての数字を直接DPで遍歴することは不可能である.各セクションについて、DPでは、このセクション自体の前と前のセクションのすべての数字を比較するだけです(各サイクルセクションには少なくとも1つの数字が追加されます).Tが100未満であれば、Tサイクル内で必ず結果が出て、直接DPすればよい.Tが大きい場合には、各サイクル数が1より大きい場合にのみ選択される.Tが100に等しいときは必ず安定した状態となり,その後,数値を最大化するために,サイクルの中で最も回数の多い数字を残りのサイクル節に挿入する.
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long int dp[105][105];
	static int data2[305];
	int data[105];
	static int maxn,n,t,mmx;
	static long long int ans;
	cin >> n >> t;
	mmx = min(n*n, n*t);

	for (size_t i = 0; i < n; i++)
	{
		cin >> data[i];
		data2[data[i]]++;
	}
	for (size_t i = 0; i < 305; i++)
	{
		maxn = max(maxn, data2[i]);
	}
	for (size_t i = 0; i <mmx/n; i++)
	{
		for (size_t s = 0; s < n; s++)
		{
			for (size_t q = 0; q < n; q++)
			{
				if (i==0)
				{
					dp[i][s] = 1;
					break;
				}
				if (data[s]>=data[q])
				{
					dp[i][s] = max(dp[i][s], dp[i - 1][q]+1);
				}
			}
			for (size_t q = 0; q < s; q++)
			{
				if (data[s] >= data[q])
				{
					dp[i][s] = max(dp[i][s], dp[i][q]+1);
				}
			}
		}
		
	}

	for (size_t i = 0; i < n; i++)
	{
		ans = max(ans, dp[mmx / n - 1][i]);
	}


	cout << ans + maxn*(t - mmx / n);
	return 0;
}