結果

問題 No.209 Longest Mountain Subsequence
ユーザー a
提出日時 2015-05-15 22:49:21
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 1,024 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 35,840 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-06 04:11:47
合計ジャッジ時間 1,232 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:36:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |   scanf("%d",&t);
      |   ~~~~~^~~~~~~~~
main.cpp:38:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
main.cpp:39:39: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |     for( int i = 0; i < n; i++ ) scanf("%d",a+i);
      |                                  ~~~~~^~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int a[111];
int dp[111][111][111];
int solve(int s,int t,int u)
{
if( u == n ) return 0;
if( dp[s][t][u] >= 0 ) return dp[s][t][u];
int res = solve(s,t,u+1);
//printf("%d %d %d\n",a[s],a[t],a[u]);
if( a[s] < a[t] ) {
if( a[t] < a[u] && a[t]-a[s] < a[u]-a[t] ) {
res = max(res,solve(t,u,u+1)+1);
}
if( a[t] > a[u] ) {
res = max(res,solve(t,u,u+1)+1);
}
}
if( a[s] > a[t] ) {
if( a[t] > a[u] && a[s]-a[t] > a[t]-a[u] ) {
res = max(res,solve(t,u,u+1)+1);
}
}
return dp[s][t][u] = res;
}
int main(void)
{
int t;
scanf("%d",&t);
while( t-- ) {
scanf("%d",&n);
for( int i = 0; i < n; i++ ) scanf("%d",a+i);
memset(dp,-1,sizeof(dp));
int res = 1;
for( int i = 0; i < n; i++ ) {
for( int j = i+1; j < n; j++ ) {
if( a[i] != a[j] ) {
res = max(res,solve(i,j,j+1)+2);
}
}
}
printf("%d\n",res);
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0