hdu 6197 array array array LIS

正反跑一次LIS,取最大的长度,如果长度大于n-k就满足条件。

ac代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <map>
#include <stack>
#include <algorithm>
using namespace std;
int dp[1001];
int LIS(int a[],int len)
{
    int ret=0;
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=len;i++)
    {
        if(a[i] > dp[ret]) dp[++ret]=a[i];
        else
        {
            int pos=lower_bound(dp+1,dp+ret,a[i])-dp;
            dp[pos]=a[i];
        }
    }
    return ret;
}
int b[100010],c[100010];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,k;
        scanf("%d %d",&n,&k);
        int pos=n-1;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&b[i]);
            c[pos--]=b[i];
        }
        int mx=max(LIS(c,n),LIS(b,n));
        if(n-mx<=k) cout<<"A is a magic array."<<endl;
        else cout<<"A is not a magic array."<<endl;
    }
    return 0;
}

心情不太好,过来这么久才整理代码。 感情这个东西,比算法难多了

时间: 2024-08-29 06:03:58

hdu 6197 array array array LIS的相关文章

hdu 5280 Senior&#39;s Array

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie gets an array $A$. Among all non-empty intervals of $A$, she wants to find the most beautiful one. She defines the beauty as the sum of the interval. Th

hdu 5280 Senior&#39;s Array(最大子段和)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5280 题意:将一个长度为n的数组,将里面某一个数改为p,使改变后最大子段和最大. 题解:dp[i]=max(dp[i-1)+a[i],a[i]),表示以第 i 个数结束的最大子段和,时间复杂度为O(n). 1)由于n<=1000,可以暴力解决,将每一个数都依次改为p,求出最大的子段和,再去这些最大子段和中最大的,时间复杂度为O(n*n); #include <iostream> #inclu

HDU 5280 Senior&#39;s Array (暴力,水)

题意:给一个数列,再给一个数字p,要求p一定要替换掉数列中的一个元素,然后求最大连续子序列之和. 思路:1000*1000的复杂度,O(n*n) .就是每个都试,然后求和. 1 #include <bits/stdc++.h> 2 #define LL long long 3 #define pii pair<int,int> 4 #define INF 0x7f7f7f7f 5 using namespace std; 6 const int N=2000; 7 int a[N]

[最大子序列和]Hdu 5280 Senior&#39;s Array

题意:一个序列,在其中一个数必须替换成给定数字p的条件下,求最大连续子序列之和. 依次把每一个数替换成p,求每次的最大连续和,找出最大值.O(n^2). #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> typedef long long ll; using namespace std; const int MAXN=1000+5; const int

hdu 5164 Matching on Array (用map实现的ac自动机)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5164 题意: 给出长度为n一个母串,给出m个长度为ki子串,匹配的条件是比率相同,如子串4 8 能和 1 2 4匹配.问所有子串在母串中出现多少次. 限制: 1 <= n,m <= 1e5 1 <= ki <= 300000 思路: 赤裸裸的ac自动机啊,不过next数组用map来实现,出题人脑洞真大. 这里有一点还要注意,hdu的g++,结构体里面不能开太大的东西,要不然他ce了还

HDU 5280 Senior&#39;s Array 最大区间和

题意:给定n个数,要求必须将其中某个数改为P,求改动后最大的区间和可以为多少. 水题.枚举每个区间,如果该区间不修改(即修改该区间以外的数),则就为该区间和,若该区间要修改,因为必须修改,所以肯定是把最小的数修改为P能保证该区间最后和最大,所以比较两种方案的较大者.对于每个区间取出的较大者,再取总共的最大者即可.注意一个trick,枚举到整个区间的时候,是必须要修改一个数的,所以这个最大的这个区间只有一种方案.先预处理1~i的区间和,维护每个区间的最小值和区间和. #include <iostr

[C++] the pointer array &amp; the array&#39;s pointer

void main(){ // the pointer array char* arry[] = { "hello", "world", "haha" }; for (int i = 0; i < 3; i++){ printf("string:%s,address:%p\n", arry[i], arry[i]); } // the array's pointer int a[10] = { 0, 1, 2, 3, 4

theme(&#39;item-list&#39;,array(&#39;items&#39;=&gt;array(&#39;aaa&#39;,&#39;bbb&#39;))) 是如何运行的 ?

$items['items'] = array( l('Configure', 'admin/config'), l('Structure', 'admin/structure'), ); $theme = theme('item_list', $items); 1,  判断是否所有的模块都加载了, if (!module_load_all(NULL) && !defined('MAINTENANCE_MODE')) { throw new Exception(t('theme() may

JavaScript定义数组的三种方式(new Array(),new Array(&#39;x&#39;,&#39;y&#39;),[&#39;x&#39;,&#39;y&#39;])

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

Linux Array & Associative Array

Ordinary Array: Assign1: arrayName=(value1 value2 ...) Assign2: arrayName[index]=value Length: ${#arrayName[*]} or ${#arrayName[@]} Indexes: ${!arrayName[*]} or ${#arrayName[@]} Example: #!/bin/bash group1=(rio amos) group2[0]=bill group2[1]=frank gr