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

为什么老是RE啊??!!!

Posted by jauhell at 2010-09-28 18:51:24 on Problem 1276
//类似于 1014 

#include <iostream>
#include <string>
using namespace std;

bool dp[100005]; 
int n[1005], D[1005], cash, N;

int main()
{
    int i, j, k, MAX;
    while(scanf("%d%d",&cash, &N)!=EOF)
    {
        for(i=0; i<N; i++)
            scanf("%d%d", n+i, D+i);
        if(!cash || !N)  { printf("0\n"); continue; }
        memset(dp, 0, sizeof(dp));
        MAX = 0;   dp[0] = 1;
        for(i=0; i<N; i++)
        {
            for(j=MAX; j>=0; j--)
            {
                if(dp[j])
                {
                    for(k=1; k<=n[i] && j+k*D[i]<=cash; k++)
                    dp[j+k*D[i]] = 1;
                }
            }
            MAX += n[i]*D[i];
        }
        i = cash;
        while(!dp[i]) i--;
        printf("%d\n", i);
    }    
    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