1 条题解
-
0
C :
#include<stdio.h> #include<stdlib.h> main() { int n,t[200],h1[200]={1},h2[200]={1},i,j,max=0,a,b,sum; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&t[i]); for(i=n;i>=1;i--) { h1[i]=1; for(j=i;j<=n;j++) if(t[i]>t[j] && h1[i]<h1[j]+1) h1[i]=h1[j]+1; } for(i=1;i<=n;i++) { h2[i]=1; for(j=1;j<=i-1;j++) if(t[i]>t[j] && h2[i]<h2[j]+1) h2[i]=h2[j]+1; } for(i=1;i<=n;i++) if(h1[i]+h2[i]>max) max=h1[i]+h2[i]; sum=n-max+1; printf("%d",sum); }
C++ :
#include<iostream> using namespace std; const int N(105); int h[N],f[N],g[N]; int main() { // ifstream cin("chorus.in"); // ofstream cout("chorus.out"); int n; while (cin>>n) { for (int i=1;i<=n;i++) cin>>h[i]; fill(f+1,f+n+1,1); //[1,n+1) fill(g+1,g+n+1,1); for (int i=2;i<=n;i++) for (int j=1;j<i;j++) if (h[j]<h[i]&&f[j]+1>f[i]) f[i]=f[j]+1; for (int i=n-1;i>=1;i--) for (int j=n;j>i;j--) if (h[j]<h[i]&&g[j]+1>g[i]) g[i]=g[j]+1; int ans(0); for (int i=1;i<=n;i++) if (f[i]+g[i]-1>ans) ans=f[i]+g[i]-1; cout<<n-ans<<endl; } // system("pause"); return 0; }
Pascal :
var n,i,j,max:longint; a,c,g:array[0..101] of longint; begin readln(n); for i:=1 to n do begin read(a[i]); g[i]:=1; c[i]:=1; end; for i:=2 to n do for j:=1 to i-1 do if (a[i]>a[j]) and (c[i]<c[j]+1) then c[i]:=c[j]+1; for i:=n-1 downto 1 do for j:=n downto i+1 do if (a[i]>a[j]) and (g[i]<g[j]+1) then g[i]:=g[j]+1; max:=1; for i:=1 to n do if c[i]+g[i]>max then max:=c[i]+g[i]; writeln(n-max+1); end.
- 1
信息
- ID
- 754
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者