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 ...
随机推荐
- wampserver更改语言步骤
wampserver更改语言步骤的具体步骤: 右击屏幕右下角图标>选择language>选择更改的语言
- 安装exe4j出现jre不匹配问题
在安装exe4j 客户端,提示如下错误: 提示的错误信息大意如下:install4j安装时,在本系统中没有找到JRE(JavaRuntime Environment)(版本要求:最低1.5,最高1.6 ...
- run loop
Objective-C之run loop详解 作者:wangzz 原文地址:http://blog.csdn.net/wzzvictory/article/details/9237973 转载请注明出 ...
- vue 画二维码
首先安装一下相关的插件 qrcode2 npm install --save qrcode2 然后在需要画二维码的页面引入一下 import QRCode from 'qrcode2' 最后在meth ...
- ruby rspec安装
在rubymine里新建Rails application
- Python Pandas库的学习(三)
今天我们来继续讲解Python中的Pandas库的基本用法 那么我们如何使用pandas对数据进行排序操作呢? food.sort_values("Sodium_(mg)",inp ...
- JavaScript - 如果...没有方法(xjl456852修改)
本文是对下面这篇文章中存在的错误进行修改,并增加少量注释. 原文出处: JavaScript - 如果...没有方法 http://www.cnblogs.com/silin6/p/4367019.h ...
- nodejs的express框架创建https服务器
一 openssl创建https私钥和证书 1.下载windows版openssl: http://slproweb.com/products/Win32OpenSSL.html Win64OpenS ...
- c#读取MySQL数据表中的内容
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 九度oj 题目1072:有多少不同的面值组合?(set集合)
题目1072:有多少不同的面值组合? 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3627 解决:1852 题目描述: 某人有8角的邮票5张,1元的邮票4张,1元8角的邮票6张,用这些邮 ...