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

跪求测试数据~一直WA!!

Posted by 11211021 at 2013-08-02 14:21:15 on Problem 1276
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int cash,N;
int d[11],n[11];
int dp[100010];
int main()
{
    while(cin>>cash>>N)
    {
        for(int i = 1 ; i <= N ; i++)
        {
            scanf("%d%d",&n[i],&d[i]);
        }
        memset(dp,0,sizeof(dp));
       // int s = 0;
        for(int i = 1; i <= N; i++)
        {
            //cout<<i<<endl;
            for(int k = 1; (k<<1) <= n[i]; k = k<<1)
            {
                //cout<<k<<endl;
                //s++;
                for(int j = cash; j >= 0; j--)
                {
                    dp[j] = dp[j];
                    if(j - k*d[i] >= 0 && dp[j - k*d[i]] + k*d[i] > dp[j])
                    {
                        //cout<<j<<' '<<k<<' '<<d[i]<<endl;
                        dp[j] = dp[j - k*d[i]] + k*d[i];
                    }
                }
                //cout<<i<<' '<<j<<' '<<dp[i][j]<<endl;
            }
        }//cout<<"!!!\n";
        printf("%d\n",dp[cash]);
    }
    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