/////该问题的关键在于颜色的分布是否连续 在不知道颜色分布是否连续的情况下 只能选择将每个颜色均作为目标颜色 而不是人为出现最多次数为目标颜色
`#include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
const int N = 1e4 + 10;
int main()
{
int t;
cin >> t;
while(t –)
{
int n, k;
cin >> n >> k;
int a[N];
for(int i = 1; i <= 60; i ++) a[i] = 0;
for(int i = 0; i < n; i ++)
{
cin >> a[i];
//cout << a[i] << " ";
}
//cout << endl;
int min_day = n;
for(int i = 1; i <= 60; i ++)
{
int day = 0;
for(int j = 0; j < n; j ++)
{
if(a[j] != i)
{
day ++;
j += k - 1;
}
}
min_day = min(min_day, day);
}
cout << min_day << endl;
}
}
**//////////////线性dp**

#include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
const int N = 1e4 + 10;
int main()
{
int n;
cin >> n;
int a[110][110];
int dp[110][110];
for(int i = 0; i < n; i ++)
{
for(int j = 0; j <= i; j ++)
{
cin >> a[i][j];
//cout << a[i][j] << " ";
}
//cout << endl;
}
for(int j = 0; j < n; j++)
dp[n-1][j] = a[n-1][j];
for(int i = n - 2; i >= 0; i --)
{
for(int j = 0; j <= i; j ++)
{
dp[i][j] = a[i][j] + max(dp[i + 1][j], dp[i + 1][j + 1]);
}
}
cout << dp[0][0];
}
`
`#include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
const int N = 1e5 + 10;
const int M = 1e9 + 7;
////使用数组前记得初始化数组
int dp[N];
int main()
{
int n, m;
cin >> n >> m;
bool a[N];
memset(a, false, sizeof(a));
memset(dp, 0, sizeof(dp));
//for(int i = 0; i <= n; i ++) dp[i] = -1;
for(int i = 0; i < m; i ++)
{
//找出破碎楼梯阶数
int x;
cin >> x;
a[x] = true;
}
dp[0] = 1;
for(int i = 1; i <= n; i ++)
{
if(a[i]) continue;
else
{
if(i == 1) dp[i] = 1;
else dp[i] = (dp[i - 1] + dp[i - 2]) % M;
}
//cout << dp[i] << " ";
}
cout << dp[n] ;
}
`
`#include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
typedef long long LL;
const int N = 1e6 + 10;
const int M = 1e9 + 7;
LL dp[N];
int n, k;
int main()
{
memset(dp, 0, sizeof(dp));
cin >> n >> k;
dp[0] = 1;
dp[1] = 2;
//从最后一个空位来分析 最后一个空位存在两个状态 放与不放 如果不放那就是看dp[i-1]个数
放的话 就得看i - k - 1这个位置的个数
for(int i = 2; i <= n; i ++)
{
if(i - k - 1 >= 0) dp[i] = (dp[i - 1] + dp[i - k - 1]) % M;
else dp[i] = (i + 1) % M ;
}
cout << dp[n];
}

//栈
#include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
typedef long long LL;
const int N = 1e6 + 10;
const int M = 1e9 + 7;
LL dp[N];
int n, k;
int main()
{
int n;
cin >> n;
string s;
cin >> s;
stack<char> t;
bool flag = true;
for(int i = 0; i < n; i ++)
{
if(s[i] == '(') t.push(s[i]);
else
{
if(!t.empty()) t.pop();
//char tmp = t.top();
}
}
if(!t.empty()) flag = false;
if(flag) cout << "Yes";
else cout << "No";
// while(!t.empty())
// {
// if(s[i] == '(') t.
// }
//cout << s;
}

//队列
#include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
typedef long long LL;
const int N = 1e6 + 10;
const int M = 1e9 + 7;
int a[1010];
bool st[1010];
int main()
{
int m, n;
cin >> m >> n;
queue[HTML_REMOVED] t;
memset(a, 0, sizeof(a));
memset(st, false, sizeof(st));
for(int i = 0; i < n; i ++) cin >> a[i];
int len = 0;
int cnt = 0;
for(int i = 0; i < n; i ++)
{
if(!st[a[i]])
{
if(len < m)
{
st[a[i]] = true;
t.push(a[i]);
len ++;
//cnt ++;
}
else
{
int k = t.front();
st[k] = false;
t.pop();
t.push(a[i]);
st[a[i]] = true;
//cnt ++;
}
cnt ++;
}
}
cout << cnt;
}
`