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 |
DP看到讨论中有提示一开始有可能在第二棵树的情况,然后又往DP的方向想,就一次AC了。。 贴代码一下,感谢那些好心提醒的人。话说英文题还就是很坏啊。。 #include <cstdio> const int maxn=2000; int a[maxn],t,w; int f1[40],f2[40]; int max(int x,int y) { if (x>y) return x; else return y; } int main() { freopen("p2385.in","r",stdin); freopen("p2385.out","w",stdout); scanf("%d%d",&t,&w); for (int i=1;i<=t;i++) { scanf("%d",&a[i]); } for (int i=1;i<=t;i++) { if (a[i]==1) { f1[0]++; for (int j=1;j<=w;j++) if ( j%2==0 ) { f1[j]=max(f1[j]+1,f1[j-1]+1); } else { f2[j]=max(f2[j]+1,f2[j-1]+1); } } else { f2[0]++; for (int j=1;j<=w;j++) if (j%2 ==0) { f2[j]=max(f2[j]+1,f2[j-1]+1); } else { f1[j]=max(f1[j]+1,f1[j-1]+1); } } } printf("%d\n", max(f1[w],f2[w]) ); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator