程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> hdu 4604 Deque

hdu 4604 Deque

編輯:C++入門知識

hdu 4604 Deque


最長上升子序列+最長遞減子序列-重復的方法不嚴謹,貌似有人已經找到反例了,至於為什麼那種方法能ac應該是測試數據弱吧

以下才是最標准的做法

//#pragma comment(linker, "/STACK:102400000,102400000")
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#ifdef _WIN32
typedef __int64 i64;
#define out64 "%I64d\n"
#define in64 "%I64d"
#else
typedef long long i64;
#define out64 "%lld\n"
#define in64 "%lld"
#endif
/************ for topcoder by zz1215 *******************/
#define foreach(c,itr)  for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define FOR(i,a,b)      for( int i = (a) ; i <= (b) ; i ++)
#define FF(i,a)         for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a,b)      for( int i = (a) ; i >= (b) ; i --)
#define S64(a)          scanf(in64,&a)
#define SS(a)           scanf("%d",&a)
#define LL(a)           ((a)<<1)
#define RR(a)           (((a)<<1)+1)
#define pb              push_back
#define pf              push_front
#define X               first
#define Y               second
#define CL(Q)           while(!Q.empty())Q.pop()
#define MM(name,what)   memset(name,what,sizeof(name))
#define MC(a,b)		memcpy(a,b,sizeof(b))
#define MAX(a,b)        ((a)>(b)?(a):(b))
#define MIN(a,b)        ((a)<(b)?(a):(b))
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)

const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
const int maxn = 101111;

int n;
int a[maxn];
vectorv;

inline void gao(int now)
{
	if (v.empty() || now >= v[v.size() - 1]){
		v.push_back(now);
	}
	else {
		v[upper_bound(v.begin(), v.end(), now) - v.begin()] = now;
	}
}

int main()
{
	int T;
	cin >> T;

	while (T--){
		cin >> n;
		for (int i = 1; i <= n; i++) {
			//cin >> a[i];
			SS(a[i]);
		}
		v.clear();
		int now;
		for (int i = n; i >= 1; i--) {
			now = 2 * a[i] + 1;
			gao(now);
		}
		for (int i = 1; i <= n; i++) {
			now = 2 * a[i];
			gao(now);
		}
		cout << v.size() << endl;
	}
	return 0;
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved