結果
| 問題 | 
                            No.209 Longest Mountain Subsequence
                             | 
                    
| コンテスト | |
| ユーザー | 
                             airis
                         | 
                    
| 提出日時 | 2015-05-16 17:17:30 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,863 bytes | 
| コンパイル時間 | 547 ms | 
| コンパイル使用メモリ | 79,652 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-06 04:56:27 | 
| 合計ジャッジ時間 | 1,383 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 2 WA * 4 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <numeric>
#include <bitset>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
int N, T;
int a[105];
int dp[105][105];
int dp2[105][105];
int dfs(int i, int j, int tdp[105][105]) {
	if (tdp[i][j] != 0) return tdp[i][j];
	int res = 1;
	int k_not_exist = 1;
	for (int k = 0; k < j; k++) {
		if (a[j] < a[i] && a[k] < a[j] && a[i]-a[j] > a[j]-a[k]) {
			res = max(res, 1 + dfs(j, k, tdp));
			k_not_exist = 0;
		}
	}
	res += k_not_exist;
	return tdp[i][j] = res;
}
int main() {
	cin >> T;
	while (T--) {
		int ans = 1;
		memset(dp, 0, sizeof(dp));
		memset(dp2, 0, sizeof(dp2));
		cin >> N;
		rep(i, N) cin >> a[i];
		//up
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < i; j++) {
				if (a[j] < a[i]) {
					dfs(i, j, dp);
				}
			}
		}
		//down
		reverse(a, a+N);
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < i; j++) {
				if (a[j] < a[i]) dfs(i, j, dp2);
			}
		}
#if 0
		rep(i, 5) rep(j, 5) {
			printf("%d%c", dp[i][j], j == 5 - 1 ? '\n' : ' ');
		}
#endif
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < i; j++) {
				for (int k = 0; k < N-i-1; k++) {
					if (dp[i][j] + dp2[N-i-1][k]-1 > ans) {
						//頂上のカウント重複のため-1
						ans = dp[i][j] + dp2[N-i-1][k]-1;
						//printf("dp[%d][%d]+dp2[%d][%d]=%d+%d=%d\n", i,j,N-i-1,k,dp[i][j],dp2[N-i-1][k],dp[i][j]+dp2[N-i-1][k]);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}
            
            
            
        
            
airis