Codeforces Round #323 (Div. 2) D. Once Again... 暴力+最长非递减子序列
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.
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).
Print a single number — the length of a sought sequence.
4 3
3 1 4 2
5
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.
题意:要你求n*T的最长非递减子序列长度
题解:由于是T个n排列,中间段必定是相同的,也必定是n排列中数最多的,在T小于100是暴力dp,大雨100时计算就好了
///
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#include<vector>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define TS printf("111111\n");
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--)
#define READ(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define mod 1000000007
#define inf 100000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//**************************************** #define maxn 100+5
int a[maxn];
int dp[];
int hashs[];
int main()
{ int n=read();
int T=read();
FOR(i,,n)
{
scanf("%d",&a[i]);
}
FOR(i,,n*)dp[i]=;
if(T<=)
{
FOR(i,,T)
{
FOR(j,,n)
{
for(int k=;k<j+n*(i-);k++)
{
int tmp=k%n;
if(tmp==)tmp=n;
if(a[j]>=a[tmp])
dp[j+n*(i-)]=max(dp[j+n*(i-)],dp[k]+);
}
}
}
int mm=-;
for(int i=;i<=n*T;i++)mm=max(dp[i],mm);
cout<<mm<<endl;
}
else { FOR(i,,)
{
FOR(j,,n)
{
for(int k=;k<j+n*(i-);k++)
{
int tmp=k%n;
if(tmp==)tmp=n;
if(a[j]>=a[tmp])
dp[j+n*(i-)]=max(dp[j+n*(i-)],dp[k]+);
}
}
}
int mm=-,flag,ans=;
for(int i=;i<=n*;i++)mm=max(dp[i],mm);
for(int i=;i<=n;i++)
{
hashs[a[i]]++;
if(hashs[a[i]]>ans)ans=hashs[a[i]];
}
cout<<mm+(T-)*ans<<endl;
}
return ;
}
代码
Codeforces Round #323 (Div. 2) D. Once Again... 暴力+最长非递减子序列的更多相关文章
- Codeforces Round #323 (Div. 1) B. Once Again... 暴力
B. Once Again... Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/582/probl ...
- Codeforces Round #323 (Div. 2) C. GCD Table 暴力
C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C ...
- Codeforces Round #323 (Div. 2) B 贪心,暴力
B. Robot's Task time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #323 (Div. 2) D. Once Again... 乱搞+LIS
D. Once Again... time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 重复T次的LIS的dp Codeforces Round #323 (Div. 2) D
http://codeforces.com/contest/583/problem/D 原题:You are given an array of positive integers a1, a2, . ...
- Codeforces Round #323 (Div. 2) C. GCD Table map
题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory l ...
- Codeforces Round #323 (Div. 2) C.GCD Table
C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is define ...
- Codeforces Round #323 (Div. 1) A. GCD Table
A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #323 (Div. 2) E - Superior Periodic Subarrays
E - Superior Periodic Subarrays 好难的一题啊... 这个博客讲的很好,搬运一下. https://blog.csdn.net/thy_asdf/article/deta ...
随机推荐
- 《BUG创造队》第五次作业:项目需求分析改进与系统设计
项目 内容 这个作业属于哪个课程 2016级软件工程 这个作业的要求在哪里 实验九 团队作业5-团队项目需求改进与系统设计 团队名称 BUG创造队 作业学习目标 1.编写完整<软件需求规格说明书 ...
- [笔记] APIO 2018 Day1
计算折纸 computaional origami 全息算法(???) margulis napkin problem 素数里有任意长的等差数列 xor gate Σxi or gate(exact ...
- 五段实用的js高级技巧
技巧一之setTimeout. 应用案例:比如你想一个函数循环执行10次,怎么办?以前通常是先setInterval,然后clearInterval,技巧一就是克服这个问题 复制代码 代码如下: (f ...
- Python之微信-微信机器人
一 简介 二 登录微信 三 微信好友男女比例 四 微信好友地域分布 五 微信聊天机器人 一 简介 wxpy基于itchat,使用了 Web 微信的通讯协议,,通过大量接口优化提升了模块的易用性,并进行 ...
- list & dictionary
list不能直接进行对应,dictionary可以 list用[],dictionary用{}
- windows窗口过程函数名词解析
windows窗口过程函数名词解析 LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) 1. LR ...
- React & search & keyboard ghost
React & search & keyboard ghost DOM events https://www.w3schools.com/jsref/dom_obj_event.asp ...
- Linux中kill,pkill,killall和xkill命令汇总讲解
终止一个进程或终止一个正在运行的程式,一般是通过 kill .killall.pkill.xkill 等进行.比如一个程式已死掉,但又不能退出,这时就应该考虑应用这些工具. 另 外应用的场合就是在服务 ...
- Thinkphp5.0 控制器向视图view赋值
Thinkphp5.0 控制器向视图view的赋值 方式一(使用fetch()方法的第二个参数赋值): <?php namespace app\index\controller; use thi ...
- JavaScript判断页面是否已经加载完毕
做页面时经常会遇到当前页面加载完成后,执行某些初始化工作.这时候就要知道如何判断页面(包括IFRAME)已经加载完成,代码如下: < script language = "javasc ...