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 ...
随机推荐
- js 上传图片、压缩、旋转
亲测 <!doctype html> <html> <head> <meta charset="utf-8"> <title& ...
- js 右键菜单
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- (十)python3 生成器
生成器(generator):在 Python 中,不必创建完整的 list,从而节省大量的空间.一边循环一边计算的机制. 创建一个 generator,有很多种方法.第一种方法很简单,只要把一个列表 ...
- Spring 和 Hibernate的整合
问题 ,spring 和 hibernate 整合 如何整合 1. Spring 使用Hibernate的的SessionFactory 2. Hibernate使用Spring提供的声明式事务
- 九度oj 题目1525:子串逆序打印
题目1525:子串逆序打印 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:3124 解决:530 题目描述: 小明手中有很多字符串卡片,每个字符串中都包含有多个连续的空格,而且这些卡片在 ...
- html的href标签不能下载apk文件
解决方案: 打开Internet 服务管理器Internet 服务管理器 网站属性 HTTP头(MIME类型) 新建 扩展名:.apk 类型(MIME): application/vnd.androi ...
- hdu 1179最大匹配
#include<stdio.h> #include<string.h> #define N 200 int map[N][N],visit[N],link[N],n,m; i ...
- 开车旅行(codevs 1199)
题目描述 Description 小A 和小B决定利用假期外出旅行,他们将想去的城市从1到N 编号,且编号较小的城市在编号较大的城市的西边,已知各个城市的海拔高度互不相同,记城市 i的海拔高度为Hi, ...
- 洛谷P1710地铁涨价
题目背景 本题开O2优化,请注意常数 题目描述 博艾市除了有海底高铁连接中国大陆.台湾与日本,市区里也有很成熟的轨道交通系统.我们可以认为博艾地铁系统是一个无向连通图.博艾有N个地铁站,同时有M小段地 ...
- 使用XML定义组件样式
<TextView android:layout_width="match_parent" android:layout_height="wrap_content& ...