Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:不得不提的= =||In Reply To:Re:调了4个小时终于过了,载在这组数据上了 Posted by:hongtrying at 2010-12-23 00:35:42 > 不是吧,有4,4是看不出去滴 这题太假了.... AC代码1: #include <stdio.h> #include <iostream> #include <algorithm> using namespace std; int main(void) { // ifstream cin("data.txt"); int DP[1001]; int DP2[1001]; double height[1001]; int n; int maxdp,maxdp2; cin>>n; for(int i=0;i<n;++i) { cin>>height[i]; } DP[0]=1; DP2[n-1]=1; for(int i=1;i<n;++i) { maxdp=1; for(int j=i-1;j>=0;--j) { if(height[i]>height[j] && DP[j]>=maxdp) maxdp=DP[j]+1; } DP[i]=maxdp; } for(int i=n-2;i>=0;--i) { maxdp2=1; for (int j=i+1;j<n;++j) { if(height[i]>height[j] && DP2[j]>=maxdp2) maxdp2=DP2[j]+1; } DP2[i]=maxdp2; } maxdp=0; int maxindex; for (int i=0;i<n;++i) { if (maxdp<=DP[i]+DP2[i]) { maxdp=DP[i]+DP2[i]; maxindex = i; } } for (int i=0;i<maxindex;++i) { if (height[i]==height[maxindex]) { ++maxdp; } } cout<<n-maxdp+1<<endl; return 0; } 6 3 5 4 4 5 3 这个代码结果是:1 AC代码2: #include <iostream> using namespace std; const int N=1005; double a[N]; int lef[N],rig[N]; int main() { int i,n,j,ans=0; scanf("%d",&n); for(i=0;i<n;i++) scanf("%lf",&a[i]); lef[0]=1; for(i=1;i<n;i++) { lef[i]=1; for(j=0;j<i;j++) if(a[i]>a[j]&&lef[j]>=lef[i]) lef[i]=lef[j]+1; } rig[n-1]=1; for(i=n-1;i>=0;i--) { rig[i]=1; for(j=n-1;j>i;j--) if(a[i]>a[j]&&rig[j]>=rig[i]) rig[i]=rig[j]+1; } for(i=0;i<n;i++) for(j=i+1;j<n;j++) if(lef[i]+rig[j]>ans) ans=lef[i]+rig[j]; printf("%d\n",n-ans); //scanf("%d",&i); return 0; } 6 3 5 4 4 5 3 结果为:2 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator