CodeForces - 583D Once Again... LIS 循环
题意:给你n个数(n<=100,ai<=300) 一个T,求n重复T次的最长非递减子序列。
题解:我直接考虑4 3 2 1 的例子,当其重复4次时会出现1 2 3 4 的子序列 ,此时再怎么重复,这也是最长的递增序列,无非是多出(T-n)个1.
所以直接不完全(不会证明地)归纳处一个答案:ans=T>n?(T-n)*M+lis(a,n*n):lis(a,n*T) .M是n个数中重复次数最多的数,lis函数输出a数列的最长非递减子序列.(考虑如果重复最多的数并非最长子序列的起始数的情况:比如1244,观察最后四个循环1244124412441244,lis不再是1244,而会自动变成44444444,所以大概是不用考虑的,反正是猜想,交一发试试呗)
坑:第一次没考虑序列重复的情况(看到ai<=300还以为是桶排);
然后ans的公式手抽写错了 写成(T-1);
最后发现
c++17.0会wa2
clang 17 dignosed 会报list的错改好后MLE 1
c++14.0缺AC了 OTZ
ac:
- #define _CRT_SECURE_NO_WARNINGS
- #include<cstdio>
- #include<algorithm>
- #include<iostream>
- #include<string>
- #include<vector>
- #include<string.h>
- using namespace std;
- typedef long long ll;
- const int maxn = + ;
- int lis[maxn*maxn], a[maxn*maxn];
- int c[], M;
- int list(int arr[], int n)
- {
- int i, j, max;
- max = ;
- for (i = ; i <= n; i++)
- lis[i] = ;
- for (i = ; i <= n; i++)
- {
- for (j = ; j<i; j++)
- {
- if (arr[i] >= arr[j] && lis[i]<lis[j] + )
- lis[i] = lis[j] + ;
- }
- }
- for (i = ; i <= n; i++)
- if (max < lis[i])
- max = lis[i];
- return max;
- }
- int main() {
- int n, t; int M;
- cin >> n >> t;
- for (int i = ; i <= n; i++)
- cin >> a[i], c[a[i]]++, M = max(M, c[a[i]]);
- for (int i = ; i <= n; i++) {
- for (int j = ; j <= n; j++) {
- a[i*n + j] = a[j];
- }
- }
- if (t > n)cout << (t - n)*M + list(a, n*n) << endl;
- else {
- cout << list(a, n*t) << endl;
- //for (int i = 1; i <= t*n; i++)cout << a[i];
- }
- cin >> n;
- }
CodeForces - 583D Once Again... LIS 循环的更多相关文章
- Codeforces 583D. Once Again... (LIS变形)
题目链接:http://codeforces.com/contest/583/problem/D 给你t个长度为n的数组.问你最长不下降子序列的长度. 一开始用第一个n数组的lis和最后一个n数组的l ...
- Codeforces Zip-line 650D 345Div1D(LIS)
传送门 大意:给出一个序列,求修改一个数过后的最长上升子序列. 思路:可以用主席树在线搞,也可以用树状数组离线搞,明显后者好写得多.我们首先读取所有的询问,然后就把询问绑在给出的位置,然后我们正向做一 ...
- 【17.07%】【codeforces 583D】Once Again...
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- python成长之路15
一:JavaScript: JavaScript是一门编程语言,浏览器内置了JavaScript语言的解释器,所以在浏览器上按照JavaScript语言的规则编写相应代码之,浏览器可以解释并做出相应的 ...
- Python 第十三篇之一:前端页面 js和dome
一:JavaScript: JavaScript是一门编程语言,浏览器内置了JavaScript语言的解释器,所以在浏览器上按照JavaScript语言的规则编写相应代码之,浏览器可以解释并做出相应的 ...
- html_Dom
Document: 每个载入浏览器的HTML文档都会成为一个Document对象. Document 对象使我们可以从脚本中对 HTML 页面中的所有元素进行访问. 并且Document 对象是 Wi ...
- (十)操作数据库、xlrd、xlwt补充
一.补充操作数据库: 1.建立游标时,指定返回的类型是字典 cur = coon.cursor(cursor=pymysql.cursors.DictCursor) 2.cur.fetchall() ...
- python学习 day6 (3月7日)
#__author : 'liuyang' #date : 2019/3/7 0007 a = ['a' , 'b' , 'c'] b = [] print(a is b ) # 空元组 可以 空列表 ...
- NOIP模拟1
期望得分:100+100+100=300 实际得分:94+96+97=287 T1 #6090. 「Codeforces Round #418」尘封思绪 #include<cstdio> ...
随机推荐
- Ubuntu Git安装与使用
本系列文章由 @yhl_leo 出品.转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50760140 本文整理和归纳了关于Ub ...
- 【安全开发】python安全编码规范
申明:本文非笔者原创,原文转载自:https://github.com/SecurityPaper/SecurityPaper-web/blob/master/_posts/2.SDL%E8%A7%8 ...
- 【RF库Collections测试】Reverse List
Name:Reverse ListSource:Collections <test library>Arguments:[ list_ ]Reverses the given list i ...
- 如何在LSI MegaRAID BIOS里设定RAID 10与Hot Spare
1. 同时按下 ”Ctrl + H” 进入MegaRAID WebBIOS 画面,可以看到所有物理硬盘 (Physical Drives) 的信息.请在左边视窗点选“Configuration Wiz ...
- Selenium 获取节点信息
Selenium 可以通过 find_element() 找到指定的节点,Selenium 也提供了相关的方法和属性来直接提取节点信息,如属性.文本等 from selenium import web ...
- [Cubieboard] 在 Cubieboard 上安装 Node.js 和 npm
你有两个选择可以实现在Cubieboard上安装NodeJS,下载别人已经编译完成适用于Cubieboard的NodeJS二进制包,或者自己下载源码自行在Cubieboard上进行编译. 使用编译完成 ...
- C语言char*字符串数组和unsigned char[]数组的相互转换
#include <iostream> #include <string> using namespace std; void convertUnCharToStr(char* ...
- Struts2(三)配置详解
一.概述 Struts2提供了多种可选的配置文件形式. 其中,struts-default.xml和default.properties是框架级别的配置文件,这两个文件在Struts的核心JAR包中, ...
- ubuntu下升级特定软件与查看软件版本信息
ubuntu 升级软件: sudo apt-get update 更新源 sudo apt-get upgrade 更新已安装的包 sudo apt-get dist-upgrade 升级系统 ubu ...
- Matlab练习——寻找完全数
clc; clear; wq = []; : sum = ; k = ; : i / sum = sum + j; end end == i wq=[wq i]; end end disp(['2至1 ...