Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

请问我的这个程序怎么就是过不了

Posted by ACM_Hohai at 2009-01-21 19:00:41 on Problem 2385
谢谢教主们帮忙看看
#include<iostream>
using namespace std;
int main()
{
    int t,w;
    int dp[2][1001][31];
    int d[1001],re;
    while(scanf("%d%d",&t,&w)!=EOF) {
        re=0;
        for(int i=0;i<t;i++) {
            scanf("%d",d+i);
            d[i]--;
        }
        dp[0][0][0]=(d[0]==0);
        dp[1][0][0]=(d[0]==1);
        for(int i=1;i<t;i++) {
            dp[0][i][0]=dp[0][i-1][0]+(d[i]==0);
            dp[1][i][0]=dp[1][i-1][0]+(d[i]==1);
            re=max(re,max(dp[0][i][0],dp[1][i][0]));
        }
        for(int i=1;i<t;i++) {
            for(int j=0;j<min(w,i);j++) {
                dp[1][i][j]=max(dp[1][i-1][j],dp[0][i-1][j-1])+(d[i]==1);
                dp[0][i][j]=max(dp[1][i-1][j-1],dp[0][i-1][j])+(d[i]==0);
                re=max(re,max(dp[0][i][j],dp[1][i][j]));
            }
        }
        printf("%d\n",re);
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator