| ||||||||||
| 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:花了一个上午搞定,效率不错!!!(一维DP,二维循环)In Reply To:花了一个上午搞定,效率不错!!!(一维DP,二维循环) Posted by:possessor at 2009-05-29 09:38:01 > #include <stdio.h>
> #include <string.h>
> #define Min(a,b) ((a)<(b))?(a):(b)
> int main()
> {
> int dp[31],n,m,i,j,x;
> while(scanf("%d%d",&n,&m)!=EOF)
> {
> memset(dp,0,sizeof(dp));
> for(i=1;i<=n;i++)
> {
> scanf("%d",&x);
> x--;
> for(j=Min(m,i);j>=0;j--)
> {
> if(x==j%2)
> dp[j]++;
> else if(j-1>=0 && dp[j-1]+1>dp[j])
> dp[j]=dp[j-1]+1;
> }
> }
> printf("%d\n",dp[m]);
> }
> return 0;
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator