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 |
first dp 超时 最后水过#include <iostream> using namespace std; int a[30002]; int b[30002]; int main() { int n; cin>>n; int i,j; int change; for(i=0;i<n;i++) cin>>a[i]; b[0] = a[0]; j=0; if(b[0]==1)change = -1; else change=0; for(i=1;i<n;i++) { if(a[i]==2) { b[++j]=a[i]; if(change==-1) change = j; } else if(a[i]==1&&change==-1)b[++j]=a[i]; else { b[change]=a[i]; change++; if(change>j) change = -1; } } cout<<n-j-1<<endl; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator