hdu 6197 array array array LIS
2017-09-13 12:13
288 查看
正反跑一次LIS,取最大的长度,如果长度大于n-k就满足条件。
ac代码:
心情不太好,过来这么久才整理代码。 感情这个东西,比算法难多了
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; }
心情不太好,过来这么久才整理代码。 感情这个东西,比算法难多了
相关文章推荐
- hdu 6197 array array array (LIS,最长上升子序列模板题)
- 【HDU 6197】array array array 【LIS】
- HDU 6197 array array array 2017沈阳网络赛 LIS
- HDU 6197 array array array(LIS)
- hdu 5532 Almost Sorted Array(LIS)
- HDU 5532 Almost Sorted Array(LIS模板题)
- HDU 6197 array array array(最长不下降子序列)
- HDU-5532 Almost Sorted Array(LIS)
- HDU 6197 array array array(最长上升或下降子序列)
- HDU 6197 LIS
- HDU-6197 - array array array - 最长上升或下降子序列
- HDU 6197 array array array (2017沈阳网赛- 最长上升子序列)
- HDU 5532 Almost Sorted Array(LIS讲解+二分)
- HDU 5532 Almost Sorted Array——LIS
- hdu 5532 Almost Sorted Array(LIS)
- HDU 5532 Almost Sorted Array (LIS)
- HDU - 6197 array array array (2017 ACM-ICPC 亚洲区 (沈阳赛区) 网络赛 1004)
- hdu 4618 Palindrome Sub-Array(dp)
- hdu 5635 LCP Array
- hdu-5635 LCP Array