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

谁给看看哪里错了runtime error

Posted by 10121540117 at 2014-04-27 16:30:43 on Problem 1742
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int dp[100020],a[100],b[100];

int cmp(const void *a,const void *b)
{
    return *(int *)a-*(int *)b;
}

using namespace std;

int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m),n || m)
    {
        int c[2000]={},i,j=1,k=0,cnt=0;
        memset(dp,0,sizeof(dp));                            //初始化
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }

        for(i=0;i<n;i++)
        {
            scanf("%d",&b[i]);
        }                                       //读入数据
        k=0;
        for(i=0;i<n;i++)
        {
            j=1;
            while(j<b[i])
            {
                c[k++]=a[i]*j;
                j<<=1;
            }
            if(j==b[i])                          //防止等于2的n次方
            {
                c[k++]=a[i];
            }
        }
        dp[1]=c[0];int t=2;
        cnt=1;
        for(i=1;i<k;i++)
        {
            int t0=t;
            for(j=0;j<t0;j++)
            {
                if(c[i]+dp[j]<=m)
                {
                    dp[t++]=c[i]+dp[j];
                }
            }
        }
        qsort(dp,t,sizeof(int),cmp);
        cnt=1;
        for(i=2;i<t;i++)
        {
            if(dp[i]!=dp[i-1])
            {
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

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